-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (30 loc) · 773 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/lib/pq"
"github.com/vldcreation/simple_bank/api"
"github.com/vldcreation/simple_bank/app"
db "github.com/vldcreation/simple_bank/db/sql/postgresql/sqlc"
)
const (
dbdriver = "postgres"
)
func main() {
var (
err error
cfg = app.NewConfigFromYaml("")
)
dbSource := "postgresql://" + cfg.DB.User + ":" + cfg.DB.Password + "@" + cfg.DB.Host + ":" + cfg.DB.Port + "/" + cfg.DB.Database + "?sslmode=disable"
conn, err := sql.Open(dbdriver, dbSource)
if err != nil {
log.Fatal("cannot connect to db: ", err)
}
store := db.NewStore(conn)
server := api.NewServer(store)
err = server.Start(fmt.Sprintf(":%s", cfg.APP.Port))
if err != nil {
log.Fatal("cannot start server: ", err)
}
}