-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (68 loc) · 1.97 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
package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"tickets/api"
"tickets/message"
"tickets/service"
"github.com/ThreeDotsLabs/go-event-driven/common/clients"
"github.com/ThreeDotsLabs/go-event-driven/common/log"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"github.com/uptrace/opentelemetry-go-extra/otelsql"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
traceHttpClient := &http.Client{Transport: otelhttp.NewTransport(
http.DefaultTransport,
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
return fmt.Sprintf("HTTP %s %s %s", r.Method, r.URL.String(), operation)
}),
)}
apiClients, err := clients.NewClientsWithHttpClient(
os.Getenv("GATEWAY_ADDR"),
func(ctx context.Context, req *http.Request) error {
req.Header.Set("Correlation-ID", log.CorrelationIDFromContext(ctx))
return nil
},
traceHttpClient,
)
if err != nil {
panic(err)
}
traceDB, err := otelsql.Open("postgres", os.Getenv("POSTGRES_URL"),
otelsql.WithAttributes(semconv.DBSystemPostgreSQL),
otelsql.WithDBName("db"))
if err != nil {
panic(err)
}
dbConn := sqlx.NewDb(traceDB, "postgres")
defer dbConn.Close()
redisClient := message.NewRedisClient(os.Getenv("REDIS_ADDR"))
defer redisClient.Close()
spreadsheetsService := api.NewSpreadsheetsAPIClient(apiClients)
receiptsService := api.NewReceiptsServiceClient(apiClients)
filesAPI := api.NewFilesApiClient(apiClients)
deadNationAPI := api.NewDeadNationClient(apiClients)
paymentsService := api.NewPaymentServiceClient(apiClients)
transportationService := api.NewTransportationClient(apiClients)
err = service.New(
dbConn,
redisClient,
spreadsheetsService,
receiptsService,
filesAPI,
deadNationAPI,
paymentsService,
transportationService,
).Run(ctx)
if err != nil {
panic(err)
}
}