You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wg-access-server/main.go

52 lines
1.2 KiB
Go

package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/pkg/errors"
"github.com/place1/wg-access-server/cmd"
"github.com/place1/wg-access-server/cmd/migrate"
"github.com/place1/wg-access-server/cmd/serve"
"github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)
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
}
}
}