-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
58 lines (45 loc) · 1.89 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
55
56
57
58
package service
// Config represents the configuration required for a service
type Config interface {
Namespace() string
}
// HTTPConfig represents the configuration required for a HTTP service
type HTTPConfig interface {
Config
BindAddr() string
CertFile() string
KeyFile() string
}
// APIConfig represents the configuration required for an API service
type APIConfig interface {
HTTPConfig
}
// WebConfig represents the configuration required for a web service
type WebConfig interface {
HTTPConfig
}
type defaultHTTPConfig struct {
BindAddr string `env:"BIND_ADDR" flag:"bind-addr" flagDesc:"Bind address"`
CertFile string `env:"CERT_FILE" flag:"cert-file" flagDesc:"Certificate file"`
KeyFile string `env:"KEY_FILE" flag:"key-file" flagDesc:"Key file"`
}
// DefaultAPIConfig is a default APIConfig implementation
type DefaultAPIConfig struct{ defaultHTTPConfig }
// BindAddr implements HTTPConfig.BindAddr
func (c DefaultAPIConfig) BindAddr() string { return c.defaultHTTPConfig.BindAddr }
// CertFile implements HTTPConfig.CertFile
func (c DefaultAPIConfig) CertFile() string { return c.defaultHTTPConfig.CertFile }
// KeyFile implements HTTPConfig.KeyFile
func (c DefaultAPIConfig) KeyFile() string { return c.defaultHTTPConfig.KeyFile }
// DefaultWebConfig is a default WebConfig implementation
type DefaultWebConfig struct {
defaultHTTPConfig
SessionSecret string `env:"SESSION_SECRET" flag:"session-secret" flagDesc:"Session secret"`
SessionName string `env:"SESSION_NAME" flag:"session-name" flagDesc:"Session name"`
}
// BindAddr implements HTTPConfig.BindAddr
func (c DefaultWebConfig) BindAddr() string { return c.defaultHTTPConfig.BindAddr }
// CertFile implements HTTPConfig.CertFile
func (c DefaultWebConfig) CertFile() string { return c.defaultHTTPConfig.CertFile }
// KeyFile implements HTTPConfig.KeyFile
func (c DefaultWebConfig) KeyFile() string { return c.defaultHTTPConfig.KeyFile }