-
Notifications
You must be signed in to change notification settings - Fork 72
/
config.go
36 lines (30 loc) · 1.33 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
package config
import (
"encoding/json"
"fmt"
"gopkg.in/validator.v2"
)
type Config struct {
Address string `json:"address" validate:"nonzero"`
Port string `json:"port" validate:"nonzero"`
ServiceDiscoveryControllerAddress string `json:"service_discovery_controller_address" validate:"nonzero"`
ServiceDiscoveryControllerPort string `json:"service_discovery_controller_port" validate:"nonzero"`
ClientCert string `json:"client_cert" validate:"nonzero"`
ClientKey string `json:"client_key" validate:"nonzero"`
CACert string `json:"ca_cert" validate:"nonzero"`
MetronPort int `json:"metron_port" validate:"min=1"`
MetricsEmitSeconds int `json:"metrics_emit_seconds" validate:"min=1"`
LogLevelAddress string `json:"log_level_address" validate:"nonzero"`
LogLevelPort int `json:"log_level_port" validate:"min=1"`
}
func NewConfig(configJSON []byte) (*Config, error) {
adapterConfig := &Config{}
err := json.Unmarshal(configJSON, adapterConfig)
if err != nil {
return nil, err
}
if err = validator.Validate(adapterConfig); err != nil {
return nil, fmt.Errorf("invalid config: %s", err)
}
return adapterConfig, err
}