-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (53 loc) · 1.27 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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"runtime"
"time"
C "sb.im/ncp/constant"
"sb.im/ncp/ncpio"
cfg "sb.im/ncp/tests/help"
)
func main() {
config_path := "config.yml"
help := flag.Bool("h", false, "this help")
debug := flag.Bool("debug", false, "use debug mode")
flag.StringVar(&config_path, "c", "config.yml", "set configuration file")
show_version := flag.Bool("v", false, "show version")
flag.Parse()
if *help {
flag.Usage()
return
}
if *show_version {
fmt.Printf("Ncp %s %s %s %s %s\n", C.Version, C.Commit, runtime.GOOS, runtime.GOARCH, C.BuildTime)
return
}
if os.Getenv("NCP_CONF") != "" {
config_path = os.Getenv("NCP_CONF")
}
log.Println("load config: " + config_path)
log.SetFlags(log.LstdFlags | log.Lshortfile)
config, err := cfg.GetConfig(config_path)
if err != nil {
panic(err)
}
//fmt.Printf("%+v", config)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ncp := ncpio.NewNcpIOs(config.NcpIO)
if *debug {
ncp.Debuger = log.New(os.Stdout, "[NCPIO] ", log.LstdFlags)
}
go ncp.Run(ctx)
// Wait mqttd server startup && sub topic on broker
time.Sleep(3 * time.Millisecond)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt)
<-sigs
log.Println("ncpio exit")
}