-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (31 loc) · 842 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 (
"context"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/minhtri6179/service/api"
db "github.com/minhtri6179/service/db/sqlc"
"github.com/minhtri6179/service/util"
"github.com/rs/zerolog/log"
)
func main() {
config, err := util.LoadConfig(".")
if err != nil {
log.Fatal().Err(err).Msg("cannot load config")
}
connPool, err := pgxpool.New(context.Background(), config.DBSource)
if err != nil {
log.Fatal().Err(err).Msg("cannot connect to db")
}
store := db.NewStore(connPool)
runGinServer(config, store)
}
func runGinServer(config util.Config, store db.Store) {
server, err := api.NewServer(config, store)
if err != nil {
log.Fatal().Err(err).Msg("cannot create server")
}
err = server.Start(config.HTTPServerAddress)
if err != nil {
log.Fatal().Err(err).Msg("cannot start server")
}
}