-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.go
53 lines (42 loc) · 1.15 KB
/
init.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
package main
import (
"runtime"
"strings"
"time"
"github.com/Akagi201/utilgo/conflag"
flags "github.com/jessevdk/go-flags"
log "github.com/sirupsen/logrus"
)
var opts struct {
Conf string `long:"conf" description:"stuns config file"`
Transport string `long:"transport" default:"udp" description:"transport protocol"`
Addr string `long:"addr" default:"0.0.0.0:3478" description:"address to listen"`
Profile bool `long:"profile" description:"whether profile or not"`
LogLevel string `long:"log_level" default:"info" description:"log level"`
}
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
}
func init() {
parser := flags.NewParser(&opts, flags.Default|flags.IgnoreUnknown)
parser.Parse()
if opts.Conf != "" {
conflag.LongHyphen = true
conflag.BoolValue = false
args, err := conflag.ArgsFrom(opts.Conf)
if err != nil {
panic(err)
}
parser.ParseArgs(args)
}
log.Debugf("stuns opts: %+v", opts)
}
func init() {
if level, err := log.ParseLevel(strings.ToLower(opts.LogLevel)); err != nil {
log.SetLevel(level)
}
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
TimestampFormat: time.RFC3339,
})
}