-
Notifications
You must be signed in to change notification settings - Fork 73
/
main.go
73 lines (64 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
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
package main
import (
"bufio"
"context"
"flag"
"log"
"os"
"strings"
"time"
"github.com/google/subcommands"
"github.com/sirupsen/logrus"
)
const (
AuthExpire = 24 * 3600 * time.Second
DefaultCleanInterval = 7200 //seconds
DefaultLanguage = "en-US"
DefaultQueryApiMaxItem = 20
DefaultMaxCallbackErrorCount = 5
)
func main() {
var (
logFile, logLevel string
)
subcommands.Register(subcommands.FlagsCommand(), "")
subcommands.Register(subcommands.HelpCommand(), "")
subcommands.Register(&servePwCmd{}, "")
subcommands.Register(&resetPwCmd{}, "")
//https://github.com/mattn/go-sqlite3/issues/39
flag.StringVar(&logFile, "log", "", "set log file, option")
flag.StringVar(&logLevel, "level", "WARN", "set loglevel, option")
flag.Parse()
switch strings.ToUpper(logLevel) {
case "DEBUG":
logrus.SetLevel(logrus.DebugLevel)
case "WARN":
logrus.SetLevel(logrus.WarnLevel)
case "INFO":
logrus.SetLevel(logrus.InfoLevel)
default:
logrus.SetLevel(logrus.WarnLevel)
}
// log & log level
{
if logFile != "" {
f, err := os.Create(logFile)
if err != nil {
log.Panicf("Open", logFile, err)
}
defer f.Close()
buf := bufio.NewWriter(f)
//async flush
go func() {
for {
time.Sleep(60 * time.Second)
buf.Flush()
}
}()
logrus.SetOutput(buf)
defer buf.Flush()
}
}
ctx := context.Background()
os.Exit(int(subcommands.Execute(ctx)))
}