-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
43 lines (39 loc) · 1022 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
package main
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
)
// Config represents the application configuration.
type Config struct {
StorageDriver string `json:"storage_driver"`
StatsD StatsDConfig `json:"statsd_server"`
HTTPPort int `json:"http_port"`
GrpcAddr string `json:"grpc_addr"`
GrpcPort int `json:"grpc_port"`
Consul ConsulConfig `json:"consul"`
}
// Entrypoint to loading server configuration.
func loadConfig(cfg string) (*Config, error) {
conf := Config{}
_, err := os.Stat(cfg)
file, err := ioutil.ReadFile(cfg)
if err != nil {
return &conf, err
}
if err = json.Unmarshal(file, &conf); err != nil {
return &conf, err
}
return &conf, nil
}
// Load the flag storage driver.
func (conf *Config) getDriver() (StorageDriver, error) {
switch conf.StorageDriver {
case "consul":
return NewConsulDriver(&conf.Consul)
case "memory":
return NewMemoryDriver()
}
return nil, errors.New("invalid driver configuration")
}