/
config.go
40 lines (35 loc) · 851 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
package offline
import "fmt"
const (
httpGatewayType = "http"
)
// Config represents Offline Storage module configuration.
type Config struct {
QueueSize int
Gateway gateway
}
type configProxy struct {
QueueSize int `yaml:"queue_size"`
Gateway *struct {
Type string `yaml:"type"`
Auth string `yaml:"auth"`
Pass string `yaml:"pass"`
} `yaml:"gateway"`
}
// UnmarshalYAML satisfies Unmarshaler interface.
func (cfg *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
p := configProxy{}
if err := unmarshal(&p); err != nil {
return err
}
cfg.QueueSize = p.QueueSize
if p.Gateway != nil {
switch p.Gateway.Type {
case httpGatewayType:
cfg.Gateway = newHTTPGateway(p.Gateway.Pass, p.Gateway.Auth)
default:
return fmt.Errorf("unrecognized offline gateway type: %s", p.Gateway.Type)
}
}
return nil
}