-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhandler.go
82 lines (68 loc) · 2.01 KB
/
handler.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
package handler
import (
"net/http"
"time"
"github.com/USACE/instrumentation-api/api/internal/cloud"
"github.com/USACE/instrumentation-api/api/internal/config"
"github.com/USACE/instrumentation-api/api/internal/middleware"
"github.com/USACE/instrumentation-api/api/internal/service"
)
func newHttpClient() *http.Client {
return &http.Client{
Timeout: time.Second * 60,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return nil
},
}
}
type ApiHandler struct {
DBService *service.DBService
Middleware middleware.Middleware
BlobService cloud.Blob
PubsubService cloud.Pubsub
Config *config.ApiConfig
}
func NewApi(cfg *config.ApiConfig) *ApiHandler {
ds := service.NewDBService(cfg.DBConfig)
return &ApiHandler{
DBService: ds,
Middleware: middleware.NewMiddleware(&cfg.ServerConfig, ds),
BlobService: cloud.NewS3Blob(&cfg.AWSS3Config, "", cfg.RoutePrefix),
PubsubService: cloud.NewSQSPubsub(&cfg.AWSSQSConfig),
Config: cfg,
}
}
type TelemetryHandler struct {
DBService *service.DBService
Middleware middleware.Middleware
}
func NewTelemetry(cfg *config.TelemetryConfig) *TelemetryHandler {
ds := service.NewDBService(cfg.DBConfig)
return &TelemetryHandler{
DBService: ds,
Middleware: middleware.NewMiddleware(&cfg.ServerConfig, ds),
}
}
type AlertCheckHandler struct {
DBService *service.DBService
Config *config.AlertCheckConfig
}
func NewAlertCheck(cfg *config.AlertCheckConfig) *AlertCheckHandler {
return &AlertCheckHandler{
DBService: service.NewDBService(cfg.DBConfig),
Config: cfg,
}
}
type DcsLoaderHandler struct {
PubsubService cloud.Pubsub
DcsLoaderService service.DcsLoaderService
}
func NewDcsLoader(cfg *config.DcsLoaderConfig) *DcsLoaderHandler {
s3Blob := cloud.NewS3Blob(&cfg.AWSS3Config, "", "")
ps := cloud.NewSQSPubsub(&cfg.AWSSQSConfig).WithBlob(s3Blob)
apiClient := newHttpClient()
return &DcsLoaderHandler{
PubsubService: ps,
DcsLoaderService: service.NewDcsLoaderService(apiClient, cfg),
}
}