-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathconfig.go
77 lines (63 loc) · 1.45 KB
/
config.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
package main
import (
"flag"
"fmt"
// _ "net/http/pprof"
"os"
"runtime/pprof"
"github.com/BurntSushi/toml"
//"go/types"
)
type TcpProxyConfig struct {
LocalBindAddr string
RemoteServerAddr string
Type string
}
type PublicServerConfig struct {
LocalBindAddr string
}
type ClientConnectConfig struct {
LocalBindAddr string
ID string
}
type NatServerConfig struct {
RemoteServerAddr string
ID string
Type string
}
type TomlConfig struct {
Mode string
PublicServerAddr string
TcpProxies map[string]TcpProxyConfig
PublicServer PublicServerConfig
NatServer map[string]NatServerConfig
ClientConnect map[string]ClientConnectConfig
}
var configOptions TomlConfig
func init() {
cpuProfile := flag.String("p", "", "write cpu profile to file")
configFile := flag.String("c", "config.toml", "config file")
mode := flag.String("m", "", "mode, can overwrite config_file's setting")
flag.Parse()
if *configFile == "" {
panic("config file is not specified")
}
if _, err := toml.DecodeFile(*configFile, &configOptions); err != nil {
// handle error
panic(err)
}
if *mode != "" {
configOptions.Mode = *mode
}
if *cpuProfile != "" {
// go func() {
// log.Println(http.ListenAndServe("localhost:6060", nil))
// }()
f, err := os.Create(*cpuProfile)
if err != nil {
fmt.Println(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
}