-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
38 lines (32 loc) · 917 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
package main
import (
"encoding/json"
"flag"
"log"
"os"
)
type Config struct {
CIDRS map[string]string `json:"cidrs"`
Resolvers map[string]ResolverConfig `json:"resolvers"`
Configuration map[string][]string `json:"configuration"`
}
type ResolverConfig struct {
Type string `json:"type"`
Socket string `json:"socket,omitempty"`
Hosts map[string]string `json:"hosts,omitempty"`
Path string `json:"path,omitempty"`
}
func LoadConfig() Config {
configFilePath := flag.String("config", "./config.json", "Path to JSON config file.")
flag.Parse()
configFile, err := os.ReadFile(*configFilePath)
if err != nil {
log.Fatalf("Unable to read config file. Error: %s", err)
}
var config Config
err = json.Unmarshal(configFile, &config)
if err != nil {
log.Fatalf("Unable to parse configuration file. Error: %s", err)
}
return config
}