-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
97 lines (87 loc) · 2.12 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
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package main
import (
"errors"
"fmt"
"os"
"github.com/spf13/pflag"
"github.com/xmidt-org/argus/auth"
"github.com/xmidt-org/argus/store"
"github.com/xmidt-org/argus/store/db"
"github.com/xmidt-org/argus/store/db/metric"
"github.com/xmidt-org/arrange"
"github.com/xmidt-org/candlelight"
"github.com/xmidt-org/touchstone"
"github.com/xmidt-org/touchstone/touchhttp"
"go.uber.org/fx"
)
const (
applicationName = "argus"
apiBase = "api/v1"
defaultKeyID = "current"
)
var (
GitCommit = "undefined"
Version = "undefined"
BuildTime = "undefined"
)
type CandlelightConfigIn struct {
fx.In
C candlelight.Config `name:"tracing_initial_config" optional:"true"`
}
func main() {
v, logger, err := setup(os.Args[1:])
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
app := fx.New(
arrange.LoggerFunc(logger.Sugar().Infof),
arrange.ForViper(v),
fx.Supply(logger),
metric.ProvideMetrics(),
auth.Provide("authx.inbound"),
touchhttp.Provide(),
touchstone.Provide(),
store.ProvideHandlers(),
db.Provide(),
fx.Provide(
consts,
arrange.UnmarshalKey("userInputValidation", store.UserInputValidationConfig{}),
arrange.UnmarshalKey("prometheus", touchstone.Config{}),
arrange.UnmarshalKey("prometheus.handler", touchhttp.Config{}),
fx.Annotated{
Name: "tracing_initial_config",
Target: arrange.UnmarshalKey("tracing", candlelight.Config{}),
},
func(in CandlelightConfigIn) candlelight.Config {
in.C.ApplicationName = applicationName
return in.C
},
candlelight.New,
),
provideServers(),
)
switch err := app.Err(); {
case errors.Is(err, pflag.ErrHelp):
return
case err == nil:
app.Run()
default:
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
}
// Provide the constants in the main package for other uber fx components to use.
type ConstOut struct {
fx.Out
APIBase string `name:"api_base"`
DefaultKeyID string `name:"default_key_id"`
}
func consts() ConstOut {
return ConstOut{
APIBase: apiBase,
DefaultKeyID: defaultKeyID,
}
}