-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (62 loc) · 1.72 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"context"
"os"
"os/signal"
"syscall"
"database/sql"
"fmt"
// "github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"
// "github.com/hibiken/asynq"
// "github.com/jackc/pgx/v5/pgxpool"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/SabariGanesh-K/prod-mgm-go/api"
db "github.com/SabariGanesh-K/prod-mgm-go/db/sqlc"
"github.com/SabariGanesh-K/prod-mgm-go/util"
"golang.org/x/sync/errgroup"
)
var interruptSignals = []os.Signal{
os.Interrupt,
syscall.SIGTERM,
syscall.SIGINT,
}
func main() {
config, err := util.LoadConfig(".")
if err != nil {
log.Fatal().Err(err).Msg("cannot load config")
}
fmt.Printf("hello")
if config.Environment == "development" {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
ctx, stop := signal.NotifyContext(context.Background(), interruptSignals...)
defer stop()
conn,err:= sql.Open(config.DBDriver,config.DBSource)
if err != nil {
log.Fatal().Err(err).Msg("cannot connect to db")
}
if err != nil {
log.Fatal().Err(err).Msg("Failed to declare a RabbitMQ queue")
}
store := db.NewStore(conn)
waitGroup, ctx := errgroup.WithContext(ctx)
// runTaskProcessor(ctx, waitGroup, config, redisOpt, store)
runGinServer(config,store )
err = waitGroup.Wait()
if err != nil {
log.Fatal().Err(err).Msg("error from wait group")
}
}
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")
}
}