-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
55 lines (45 loc) · 1.06 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 (
"flag"
"github.com/pcmid/mdns/core"
log "github.com/sirupsen/logrus"
"io"
"os"
)
// go build -ldflags "-X main.version=version"
var version = ""
func main() {
var (
configPath string
logPath string
isLogVerbose bool
isShowVersion bool
)
flag.StringVar(&configPath, "c", "./config.json", "config file path")
flag.StringVar(&logPath, "l", "", "log file path")
flag.BoolVar(&isLogVerbose, "v", false, "verbose mode")
flag.BoolVar(&isShowVersion, "V", false, "current version of mdns")
flag.Parse()
if isShowVersion {
println(version)
return
}
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
if isLogVerbose {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
if logPath != "" {
lf, err := os.OpenFile(logPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0640)
if err != nil {
println("Logfile error: Please check your log file path")
} else {
log.SetOutput(io.MultiWriter(lf, os.Stdout))
}
}
core.InitServer(configPath).Run()
}