-
Notifications
You must be signed in to change notification settings - Fork 489
/
config.go
77 lines (63 loc) · 1.85 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package server
import (
"flag"
"github.com/weaveworks/common/logging"
)
// Config holds dynamic configuration options for a Server.
type Config struct {
LogLevel logging.Level `yaml:"log_level"`
LogFormat logging.Format `yaml:"log_format"`
GRPC GRPCConfig `yaml:",inline"`
HTTP HTTPConfig `yaml:",inline"`
// Flags is a DEPRECATED field holding static coniguration options.
// It will be removed from YAML and only be exposed by command-line flags in
// v0.26.0.
//
// Updating any field found in Flags will cause updating the Server to fail.
Flags Flags `yaml:",inline"`
}
// UnmarshalYAML unmarshals the server config with defaults applied.
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultConfig
type config Config
return unmarshal((*config)(c))
}
// HTTPConfig holds dynamic configuration options for the HTTP server.
type HTTPConfig struct {
TLSConfig TLSConfig `yaml:"http_tls_config"`
}
// GRPCConfig holds dynamic configuration options for the gRPC server.
type GRPCConfig struct {
TLSConfig TLSConfig `yaml:"grpc_tls_config"`
}
// Default configuration structs.
var (
DefaultConfig = Config{
GRPC: DefaultGRPCConfig,
HTTP: DefaultHTTPConfig,
Flags: DefaultFlags,
LogLevel: DefaultLogLevel,
LogFormat: DefaultLogFormat,
}
DefaultHTTPConfig = HTTPConfig{
// No non-zero defaults yet
}
DefaultGRPCConfig = GRPCConfig{
// No non-zero defaults yet
}
emptyFlagSet = flag.NewFlagSet("", flag.ExitOnError)
DefaultLogLevel = func() logging.Level {
var lvl logging.Level
lvl.RegisterFlags(emptyFlagSet)
return lvl
}()
DefaultLogFormat = func() logging.Format {
var fmt logging.Format
fmt.RegisterFlags(emptyFlagSet)
return fmt
}()
)
// RegisterFlags registers flags for c to the given FlagSet.
func (c *Config) RegisterFlags(f *flag.FlagSet) {
c.Flags.RegisterFlags(f)
}