-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
48 lines (37 loc) · 955 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
43
44
45
46
47
48
package main
// Defines a function to parse the JSON proxies and chains configuration file and a structure to store the parsed configuration
import (
"bytes"
"encoding/json"
"fmt"
"os"
"sync"
)
type chainsConf struct {
proxychains map[string]proxyChain
valid bool // whether the current configuration is valid
mu sync.RWMutex
}
type mainConfig struct {
Proxies proxyMap
Chains chainMap
Routes routing
Servers []server
Hosts hostMap
}
func parseMainConfig(configPath string) (mainConfig, error) {
var config mainConfig
fileBytes, err := os.ReadFile(configPath)
if err != nil {
err := fmt.Errorf("error reading file %v : %v", configPath, err)
return config, err
}
dec := json.NewDecoder(bytes.NewReader(fileBytes))
dec.DisallowUnknownFields()
err = dec.Decode(&config)
if err != nil {
err = fmt.Errorf("error unmarshalling server config file : %v", err)
return config, err
}
return config, nil
}