forked from shadowsocks/go-shadowsocks2
-
Notifications
You must be signed in to change notification settings - Fork 36
/
configure.go
69 lines (59 loc) · 1.42 KB
/
configure.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
package main
import (
"encoding/json"
"io/ioutil"
"os"
)
type Configure struct {
Client string `json:"client"`
Server string `json:"server"`
Cipher string `json:"cipher"`
Key string `json:"key"`
Password string `json:"password"`
Keygen int `json:"keygen"`
Socks string `json:"socks"`
RedirTCP string `json:"redir_tcp"`
RedirTCP6 string `json:"redir_tcp_6"`
TCPTun string `json:"tcp_tun"`
UDPTun string `json:"udp_tun"`
UDPSocks bool `json:"udp_socks"`
UDP bool `json:"udp"`
TCP bool `json:"tcp"`
Plugin string `json:"plugin"`
PluginOpts string `json:"plugin_opts"`
Verbose bool `json:"verbose"`
UDPTimeout Duration `json:"udp_timeout"`
TCPCork bool `json:"tcp_cork"`
}
var (
config Configure
)
func loadConfigure(filePath string) *Configure {
var (
content []byte
err error
)
if !exists(filePath) {
logf(filePath + " is not exits")
return nil
}
if content, err = ioutil.ReadFile(filePath); err != nil {
logf("Error reading configuration file, err is " + err.Error())
return nil
}
if err := json.Unmarshal(content, &config); err != nil {
logf("Error decoding json file, err is :" + err.Error())
return nil
}
return &config
}
func exists(path string) bool {
_, err := os.Stat(path)
if err != nil {
if os.IsExist(err) {
return true
}
return false
}
return true
}