-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.go
90 lines (75 loc) · 2.07 KB
/
proxy.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
89
90
package main
import (
"flag"
"fmt"
"github.com/zyong/miniproxygo/m_debug"
"path"
"runtime"
"time"
)
import (
"github.com/baidu/go-lib/log"
"github.com/baidu/go-lib/log/log4go"
)
import (
"github.com/zyong/miniproxygo/m_config"
"github.com/zyong/miniproxygo/m_server"
"github.com/zyong/miniproxygo/m_util"
)
var (
help = flag.Bool("h", false, "to show help")
confRoot = flag.String("c", "./conf", "root path of configuration")
logPath = flag.String("l", "./log", "dir path of log")
stdOut = flag.Bool("s", false, "to show log in stdout")
showVersion = flag.Bool("v", false, "to show version of proxy")
showVerbose = flag.Bool("V", false, "to show verbose information about proxy")
debugLog = flag.Bool("d", false, "to show debug log (otherwise >= info)")
)
var version string = "0.1"
func main() {
var err error
var config m_config.Conf
var logSwitch string
flag.Parse()
if *help {
flag.PrintDefaults()
return
}
if *showVerbose {
fmt.Printf("go version: %s\n", runtime.Version())
return
}
// debug switch
if *debugLog {
logSwitch = "DEBUG"
m_debug.DebugIsOpen = true
} else {
logSwitch = "INFO"
m_debug.DebugIsOpen = false
}
// initialize log
log4go.SetLogBufferLength(10000)
log4go.SetLogWithBlocking(false)
log4go.SetLogFormat(log4go.FORMAT_DEFAULT_WITH_PID)
log4go.SetSrcLineForBinLog(false)
err = log.Init("proxy", logSwitch, *logPath, *stdOut, "midnight", 7)
if err != nil {
fmt.Printf("proxy: err in log.Init():%s\n", err.Error())
m_util.AbnormalExit()
}
log.Logger.Info("proxy[version:%s] start", version)
// load server config
confPath := path.Join(*confRoot, "proxy.conf")
config, err = m_config.ConfigLoad(confPath, *confRoot, m_config.SetDefaultConfig)
if err != nil {
log.Logger.Error("main(): in Server ConfigLoad():%s", err.Error())
m_util.AbnormalExit()
}
// start and serve
if err = m_server.Start(config, version, *confRoot); err != nil {
log.Logger.Error("main(): server.StartUp(): %s", err.Error())
}
// waiting for logger finish jobs
time.Sleep(1 * time.Second)
log.Logger.Close()
}