forked from EmbarkStudios/wg-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (48 loc) · 1.24 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
package main
import (
"strings"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/bcrypt"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
logLevel = kingpin.Flag("log-level", "The level of logging").Default("info").Enum("debug", "info", "warn", "error", "panic", "fatal")
)
func main() {
kingpin.HelpFlag.Short('h')
kingpin.CommandLine.DefaultEnvars()
kingpin.Command("server", "Start server.").Default()
passwdCmd := kingpin.Command("passwd", "Generate password hash.")
passwdCmdPassword := passwdCmd.Arg("password", "The password to hash").Required().String()
cmd := kingpin.Parse()
switch strings.ToLower(*logLevel) {
case "debug":
log.SetLevel(log.DebugLevel)
case "warn":
log.SetLevel(log.WarnLevel)
case "error":
log.SetLevel(log.ErrorLevel)
case "panic":
log.SetLevel(log.PanicLevel)
default:
log.SetLevel(log.InfoLevel)
}
switch cmd {
case "passwd":
bytes, err := bcrypt.GenerateFromPassword([]byte(*passwdCmdPassword), 14)
if err != nil {
log.Fatalf("generate password error: %v", err)
}
log.Infof("Password Hash: %s", string(bytes))
return
case "server":
log.Info("Starting")
server := NewServer()
err := server.Start()
if err != nil {
log.Fatal(err)
}
default:
log.Fatal("Unknown command")
}
}