-
Notifications
You must be signed in to change notification settings - Fork 223
/
config.go
78 lines (58 loc) · 1.45 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
78
package flyctl
import (
"github.com/spf13/viper"
)
const (
ConfigAPIToken = "access_token"
ConfigAPIBaseURL = "api_base_url"
ConfigAppName = "app"
ConfigVerboseOutput = "verbose"
ConfigJSONOutput = "json"
ConfigBuiltinsfile = "builtins_file"
ConfigGQLErrorLogging = "gqlerrorlogging"
ConfigInstaller = "installer"
BuildKitNodeID = "buildkit_node_id"
ConfigWireGuardState = "wire_guard_state"
ConfigRegistryHost = "registry_host"
)
const NSRoot = "flyctl"
type Config interface {
GetString(key string) string
GetBool(key string) bool
GetStringSlice(key string) []string
GetInt(key string) int
IsSet(key string) bool
}
type config struct {
ns string
}
func (cfg *config) nsKey(key string) string {
if cfg.ns == NSRoot {
return key
}
return cfg.ns + "." + key
}
func (cfg *config) GetString(key string) string {
fullKey := cfg.nsKey(key)
return viper.GetString(fullKey)
}
func (cfg *config) GetBool(key string) bool {
fullKey := cfg.nsKey(key)
return viper.GetBool(fullKey)
}
func (cfg *config) GetStringSlice(key string) []string {
fullKey := cfg.nsKey(key)
return viper.GetStringSlice(fullKey)
}
func (cfg *config) GetInt(key string) int {
fullKey := cfg.nsKey(key)
return viper.GetInt(fullKey)
}
func (cfg *config) IsSet(key string) bool {
fullKey := cfg.nsKey(key)
return viper.IsSet(fullKey)
}
func ConfigNS(ns string) Config {
return &config{ns}
}
var FlyConfig Config = ConfigNS(NSRoot)