diff --git a/backend/server/main.go b/backend/server/main.go index 2c7abd5..88fd612 100644 --- a/backend/server/main.go +++ b/backend/server/main.go @@ -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" ) @@ -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") diff --git a/backend/server/util/config.go b/backend/server/util/config.go index c9cfeff..46a829f 100644 --- a/backend/server/util/config.go +++ b/backend/server/util/config.go @@ -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"`