Skip to content

Commit

Permalink
Initialiaze db conn with api server
Browse files Browse the repository at this point in the history
  • Loading branch information
Aadesh-Baral committed Aug 25, 2022
1 parent ea9b108 commit afbe6f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion backend/server/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package main

import (
"database/sql"
"log"

"github.com/baato/before-after/api"
db "github.com/baato/before-after/db/sqlc"
"github.com/baato/before-after/util"
)

Expand All @@ -12,7 +14,14 @@ func main() {
if err != nil {
log.Fatal("cannot load config:", err)
}
server := api.NewServer(&config)

conn, err := sql.Open(config.DBDriver, config.DBSource)
if err != nil {
log.Fatalf("cannot connect to db:%v", err)
}
query := db.New(conn)

server := api.NewServer(query, &config)

// Start listening for incoming chat messages
server.Start(":8848")
Expand Down
2 changes: 2 additions & 0 deletions backend/server/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
// Config stores all configuration of the application.
// The values are read by viper from a config file or environment variable.
type Config struct {
DBDriver string `mapstructure:"DB_DRIVER"`
DBSource string `mapstructure:"DB_SOURCE"`
HostProtocol string `mapstructure:"HOST_PROTOCOL"`
HostIP string `mapstructure:"HOST_IP"`
SMTPHost string `mapstructure:"SMTP_HOST"`
Expand Down

0 comments on commit afbe6f3

Please sign in to comment.