forked from ionorg/ion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
86 lines (71 loc) · 1.41 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
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
log "github.com/pion/ion-log"
"github.com/pion/ion/pkg/node/islb"
"github.com/spf13/viper"
)
var (
conf = islb.Config{}
file string
)
func showHelp() {
fmt.Printf("Usage:%s {params}\n", os.Args[0])
fmt.Println(" -c {config file}")
fmt.Println(" -h (show help info)")
}
func load() bool {
_, err := os.Stat(file)
if err != nil {
return false
}
viper.SetConfigFile(file)
viper.SetConfigType("toml")
err = viper.ReadInConfig()
if err != nil {
fmt.Printf("config file %s read failed. %v\n", file, err)
return false
}
err = viper.UnmarshalExact(&conf)
if err != nil {
fmt.Printf("config file %s loaded failed. %v\n", file, err)
return false
}
fmt.Printf("config %s load ok!\n", file)
return true
}
func parse() bool {
flag.StringVar(&file, "c", "configs/islb.toml", "config file")
help := flag.Bool("h", false, "help info")
flag.Parse()
if !load() {
return false
}
if *help {
showHelp()
return false
}
return true
}
func main() {
if !parse() {
showHelp()
os.Exit(-1)
}
log.Init(conf.Log.Level)
log.Infof("--- starting islb node ---")
node := islb.NewISLB()
if err := node.Start(conf); err != nil {
log.Errorf("islb start error: %v", err)
os.Exit(-1)
}
defer node.Close()
// Press Ctrl+C to exit the process
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
<-ch
}