-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
91 lines (78 loc) · 1.99 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
package main
import (
"os"
"github.com/freemiumvpn/fpn-auth/internal/client"
"github.com/freemiumvpn/fpn-auth/shared/logger"
"github.com/freemiumvpn/fpn-auth/shared/prometheus"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"golang.org/x/sync/errgroup"
)
const (
appName = "fpn-auth"
appVersion = "0.1.0"
)
var (
config struct {
LogLevel string
LogOutput string
AddressPrometheus string
AddressClient string
}
appFlags = []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Usage: "Log Level",
EnvVars: []string{"LOG_LEVEL"},
Value: "info",
Destination: &config.LogLevel,
},
&cli.StringFlag{
Name: "log-output",
Usage: "Log Output (text, json)",
EnvVars: []string{"LOG_OUTPUT"},
Value: "json",
Destination: &config.LogOutput,
},
&cli.StringFlag{
Name: "prometheus-address",
Usage: "Prometheus Address exposes '/__/metrics' ",
EnvVars: []string{"PROMETHEUS_ADDRESS"},
Value: ":8081",
Destination: &config.AddressPrometheus,
},
&cli.StringFlag{
Name: "client-address",
Usage: "Client Address exposes the vpn wrapper",
EnvVars: []string{"CLIENT_ADDRESS"},
Value: ":8989",
Destination: &config.AddressClient,
},
}
)
func appAction(cliCtx *cli.Context) error {
if err := logger.New(config.LogLevel, config.LogOutput); err != nil {
return err
}
ctx := cliCtx.Context
errorGroup, ctx := errgroup.WithContext(ctx)
metrics := prometheus.New(ctx, config.AddressPrometheus)
authClient := client.New(ctx, config.AddressClient)
errorGroup.Go(func() error {
return metrics.Serve(ctx)
})
errorGroup.Go(func() error {
return authClient.Serve()
})
return errorGroup.Wait()
}
func main() {
app := cli.NewApp()
app.Name = appName
app.Flags = appFlags
app.Version = appVersion
app.Action = appAction
if err := app.Run(os.Args); err != nil {
logrus.WithError(err).Fatal("Failed to run service")
}
}