-
Notifications
You must be signed in to change notification settings - Fork 60
/
config.go
54 lines (48 loc) · 1.26 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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
)
// Config parameters
var serverConfig = Configuration{}
var reg Registry
func loadConfig() {
file, e := ioutil.ReadFile(*configFile)
if e != nil {
fmt.Printf("File error: %v\n", e)
os.Exit(1)
}
//fmt.Printf("Loaded Config: \n%s\n", string(file))
json.Unmarshal(file, &serverConfig)
fmt.Printf("succeeded to read the config: %s\n", *configFile)
switch serverConfig.RegistryType {
case "zookeeper":
reg = &ZooKeeperRegistry{}
case "etcd":
reg = &EtcdRegistry{}
case "etcdv3":
reg = &EtcdV3Registry{}
case "consul":
reg = &ConsulRegistry{}
default:
fmt.Printf("unsupported registry: %s\n", serverConfig.RegistryType)
os.Exit(2)
}
if !strings.HasSuffix(serverConfig.ServiceBaseURL, "/") {
serverConfig.ServiceBaseURL += "/"
}
reg.initRegistry()
}
// Configuration is configuration strcut refects the config.json
type Configuration struct {
RegistryType string `json:"registry_type"`
RegistryURL string `json:"registry_url"`
ServiceBaseURL string `json:"service_base_url"`
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
User string `json:"user,omitempty"`
Password string `json:"password,omitempty"`
}