-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathconfig.go
More file actions
51 lines (46 loc) · 881 Bytes
/
Copy pathconfig.go
File metadata and controls
51 lines (46 loc) · 881 Bytes
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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
type proxy struct {
Address string
Port int
User string
Pass string
}
type proxyPair struct {
Socks proxy
HTTP proxy
}
type config struct {
Log struct {
Dir string
Level string
}
Settings struct {
ReadBufferSize int
WriteBufferSize int
}
Proxies []proxyPair
}
func makeConfig(configPath string) *config {
configData, err := ioutil.ReadFile(configPath)
if err != nil {
fmt.Fprintf(os.Stderr, "fail to read config file %s with error %s\n", configPath, err)
os.Exit(1)
}
config := &config{}
err = json.Unmarshal(configData, config)
if err != nil {
fmt.Fprintf(os.Stderr, "fail to parse config file %s with error %s\n", configPath, err)
os.Exit(1)
}
if len(config.Log.Dir) == 0 {
fmt.Fprintf(os.Stderr, "no log path specifled\n")
os.Exit(1)
}
return config
}