-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (71 loc) · 2.14 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
package main
import (
"flag"
"fmt"
"path/filepath"
"runtime"
"strings"
"github.com/kobehaha/tcp-proxy-system/config"
"github.com/kobehaha/tcp-proxy-system/hack"
"github.com/kobehaha/tcp-proxy-system/log"
"github.com/kobehaha/tcp-proxy-system/server"
"github.com/kobehaha/tcp-proxy-system/util"
)
// description
// define default config
const (
DefaultConfigFile = "../conf/default.json"
DefaultLogFileLocation = "../logs"
DefaultLogName = "proxy.log"
Start = "start"
Stop = "stop"
Status = "status"
)
const banner string = `
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx WELCOME USE TCP PROXY xxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
`
// descrition
// main
func main() {
var cmdConfigFile string
var cmd string
var configInfo *config.Config
var err interface{}
var defaultPath string
flag.StringVar(&cmdConfigFile, "conf", DefaultConfigFile, "-conf config path location")
flag.StringVar(&cmd, "s", "start", "-s define start|stop|status")
flag.Parse()
fmt.Println(banner)
fmt.Printf("version : %s\n", hack.Version)
fmt.Printf("Build Info: %s\n", hack.Compile)
if strings.Compare(cmdConfigFile, DefaultConfigFile) == 0 {
defaultPath = util.DefaultPath()
configInfo, err = config.Load(filepath.Join(defaultPath, DefaultConfigFile))
} else {
configInfo, err = config.Load(cmdConfigFile)
}
if err != nil {
fmt.Println("tcp proxy boostrap failed : %s\n", err)
}
init_log(configInfo)
runtime.GOMAXPROCS(configInfo.MaxProcessor)
proxy := &server.ProxyServer{}
proxy.Init(configInfo)
proxy.WatchStopSignal()
proxy.Start()
}
func init_log(config *config.Config) {
// log
logfile := config.LogFile
if logfile == "" {
log.Init(DefaultLogName, DefaultLogFileLocation)
} else {
log.Init(DefaultLogName, logfile)
}
}