-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (40 loc) · 1.43 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
package main
import (
"github.com/aku-ato/scanner/app/mortar"
"github.com/alecthomas/kong"
"github.com/go-masonry/mortar/providers"
"go.uber.org/fx"
)
var CLI struct {
Config struct {
Path string `arg:"" required:"" help:"Path to config file." type:"existingfile"`
AdditionalFiles []string `optional:"" help:"Additional configuration files to merge, comma separated" type:"existingfile"`
} `cmd:"" help:"Path to config file."`
}
func main() {
ctx := kong.Parse(&CLI, kong.UsageOnError())
switch cmd := ctx.Command(); cmd {
case "config <path>":
app := createApplication(CLI.Config.Path, CLI.Config.AdditionalFiles)
app.Run()
default:
ctx.Fatalf("unknown option %s", cmd)
}
}
func createApplication(configFilePath string, additionalFiles []string) *fx.App {
return fx.New(
// fx.NopLogger, // remove fx debug
mortar.ViperFxOption(configFilePath, additionalFiles...), // Configuration map
mortar.LoggerFxOption(), // Logger
mortar.PrometheusFxOption(), // Prometheus
mortar.HttpClientFxOptions(),
mortar.HttpServerFxOptions(),
mortar.AuthFxOptions(),
mortar.InternalHttpHandlersFxOptions(),
mortar.CustomHandlersFxOptions(),
// Tutorial service dependencies
mortar.ServiceAPIsAndOtherDependenciesFxOption(), // register tutorial APIs
// This one invokes all the above
providers.BuildMortarWebServiceFxOption(), // http server invoker
)
}