-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (38 loc) · 1.18 KB
/
Copy pathmain.go
File metadata and controls
48 lines (38 loc) · 1.18 KB
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
package main
import (
"context"
"database/sql"
"os/signal"
"syscall"
"github.com/rs/zerolog/log"
"github.com/simplebank/cmd"
"github.com/simplebank/config"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"
_ "github.com/jackc/pgx/v4/stdlib" // For pqx driver through sql
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)
func main() {
var db *sql.DB
ctx := context.Background()
appConfig, err := config.New()
if err != nil {
panic(err) // TODO: replace it with zap or logrus. preferably zap
}
ctx, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer stop()
tracerProvider, propagator := cmd.InitOtel()
transport := otelhttp.NewTransport(cmd.DefaultPooledTransport(), otelhttp.WithTracerProvider(tracerProvider), otelhttp.WithPropagators(propagator))
db, err = sql.Open("pgx", appConfig.DBUrl)
if err != nil {
log.Err(err).Msg("database connection error")
panic(err)
}
// Establish database connection
err = db.PingContext(ctx)
if err != nil {
log.Err(err).Msg("ping error")
panic(err)
}
_ = cmd.Execute(ctx, appConfig, tracerProvider, propagator, transport, db)
}