forked from Place1/wg-access-server
-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.go
52 lines (44 loc) · 1.26 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
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/alecthomas/kingpin/v2"
"github.com/freifunkMUC/wg-access-server/cmd"
"github.com/freifunkMUC/wg-access-server/cmd/migrate"
"github.com/freifunkMUC/wg-access-server/cmd/serve"
)
var (
app = kingpin.New("wg-access-server", "An all-in-one WireGuard Access Server & VPN solution")
logLevel = app.Flag("log-level", "Log level: trace, debug, info, error, fatal").Envar("WG_LOG_LEVEL").Default("info").String()
)
func main() {
// All the subcommands for wg-access-server
commands := []cmd.Command{
serve.Register(app),
migrate.Register(app),
}
// Parse CLI arguments
clicmd := kingpin.MustParse(app.Parse(os.Args[1:]))
// Set global log level
level, err := logrus.ParseLevel(*logLevel)
if err != nil {
logrus.Fatal(errors.Wrap(err, "invalid log level - should be one of fatal, error, warn, info, debug, trace"))
}
logrus.SetLevel(level)
logrus.SetReportCaller(true)
logrus.SetFormatter(&logrus.TextFormatter{
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
return "", fmt.Sprintf("%s:%d", filepath.Base(f.File), f.Line)
},
})
for _, c := range commands {
if clicmd == c.Name() {
c.Run()
return
}
}
}