-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
88 lines (67 loc) · 1.44 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
87
88
package main
import (
"flag"
"fmt"
"net/http"
"octlink/ovs/api"
"octlink/ovs/plugins"
"octlink/ovs/utils"
"octlink/ovs/utils/configuration"
"octlink/ovs/utils/octlog"
"octlink/ovs/utils/vyos"
)
var (
port int
addr string
config string
)
var conf *configuration.Configuration
func initDebugConfig() {
octlog.InitDebugConfig(conf.DebugLevel)
}
func initLogConfig() {
utils.CreateDir(configuration.LogDirectory())
api.InitLog(conf.LogLevel)
utils.InitLog(conf.LogLevel)
vyos.InitLog(conf.LogLevel)
plugins.InitLog(conf.LogLevel)
}
func initDebugAndLog() {
initDebugConfig()
initLogConfig()
}
func init() {
flag.StringVar(&config, "config", "./config.yml", "Config file path")
}
func usage() {
fmt.Printf(" RVM Store of V" + utils.Version() + "\n")
fmt.Printf(" ./ovs -config ./config.yml\n")
flag.PrintDefaults()
}
func runAPIThread() {
api := &api.API{
Name: "OVS API Server",
}
server := &http.Server{
Addr: fmt.Sprintf("%s", conf.HTTP.Addr),
Handler: api.Router(),
MaxHeaderBytes: 1 << 20,
}
octlog.Warn("OVS API Engine Started ON %s\n", conf.HTTP.Addr)
err := server.ListenAndServe()
if err != nil {
octlog.Error("error to listen at %s\n", conf.HTTP.Addr)
}
}
func main() {
flag.Usage = usage
flag.Parse()
c, err := configuration.ResolveConfig(config)
if err != nil {
fmt.Printf("Resolve Configuration Error[%s]\n", err)
return
}
conf = c
initDebugAndLog()
runAPIThread()
}