-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfig.go
56 lines (49 loc) · 1.34 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
package main
import (
"github.com/ssoor/socks/upstream"
"encoding/json"
"io/ioutil"
)
type Upstream struct {
Type string `json:"type"`
Crypto string `json:"crypto"`
Password string `json:"password"`
Address string `json:"address"`
}
type PACRule struct {
Name string `json:"name"`
Proxy string `json:"proxy"`
SOCKS4 string `json:"socks4"`
SOCKS5 string `json:"socks5"`
LocalRules string `json:"local_rule_file"`
RemoteRules string `json:"remote_rule_file"`
}
type PAC struct {
Rules []PACRule `json:"rules"`
Address string `json:"address"`
Upstream Upstream `json:"upstream"`
}
type Proxy struct {
HTTP string `json:"http"`
SOCKS4 string `json:"socks4"`
SOCKS5 string `json:"socks5"`
Crypto string `json:"crypto"`
Password string `json:"password"`
DNSCacheTimeout int `json:"dnsCacheTimeout"`
Upstreams []upstream.Upstream `json:"upstreams"`
}
type Config struct {
PAC PAC `json:"pac"`
Proxies []Proxy `json:"proxies"`
}
func LoadConfig(s string) (*Config, error) {
data, err := ioutil.ReadFile(s)
if err != nil {
return nil, err
}
cfgGroup := &Config{}
if err = json.Unmarshal(data, cfgGroup); err != nil {
return nil, err
}
return cfgGroup, nil
}