forked from shadowsocks/shadowsocks-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
42 lines (39 loc) · 1010 Bytes
/
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
/**
* Created with IntelliJ IDEA.
* User: clowwindy
* Date: 12-11-2
* Time: 上午10:31
* To change this template use File | Settings | File Templates.
*/
package shadowsocks
import (
"encoding/json"
"io/ioutil"
"log"
"os"
)
type Config struct {
Server string `json:"server"`
ServerPort int `json:"server_port"`
LocalPort int `json:"local_port"`
Password string `json:"password"`
PortPassword map[string]string `json:"port_password"`
Debug bool `json:"debug"`
}
func ParseConfig(path string) *Config {
file, err := os.Open(path) // For read access.
if err != nil {
log.Fatal("error opening config file:", err)
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
log.Fatalln("error reading config:", err)
}
var config Config
if err = json.Unmarshal(data, &config); err != nil {
log.Fatalln("can not parse config:", err)
}
Debug = DebugLog(config.Debug)
return &config
}