-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
40 lines (34 loc) · 915 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
40
package main
import (
"database/sql"
"log"
_ "github.com/golang/mock/mockgen/model"
_ "github.com/lib/pq"
"github.com/samirprakash/go-bank/api"
db "github.com/samirprakash/go-bank/db/sqlc"
"github.com/samirprakash/go-bank/util"
)
func main() {
// load config from file or env vars using viper
config, err := util.LoadConfig(".")
if err != nil {
log.Fatal("Not able to load config", err)
}
// connect to the database
conn, err := sql.Open(config.DBDriver, config.DBSource)
if err != nil {
log.Fatal("cannot connect to database", err)
}
// create a database store for executing queries
store := db.NewStore(conn)
// create a server connected to the store
server, err := api.NewServer(config, store)
if err != nil {
log.Fatal("cannot create server : ", err)
}
// start the server
err = server.Start(config.ServerAddress)
if err != nil {
log.Fatal("cannot start server", err)
}
}