File tree Expand file tree Collapse file tree 5 files changed +29
-32
lines changed Expand file tree Collapse file tree 5 files changed +29
-32
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "fmt"
5
-
4
+ "github.com/deis/steward/config"
6
5
"github.com/juju/loggo"
7
- "github.com/kelseyhightower/envconfig"
8
6
)
9
7
10
- type errModeUnsupported struct {
11
- mode string
12
- }
13
-
14
- func (e errModeUnsupported ) Error () string {
15
- return fmt .Sprintf ("mode '%s' is unsupported" , e .mode )
16
- }
17
-
18
- type config struct {
8
+ type rootConfig struct {
19
9
Mode string `envconfig:"MODE" default:"cf"`
20
10
LogLevel string `envconfig:"LOG_LEVEL" default:"info"`
21
11
WatchNamespaces []string `envconfig:"WATCH_NAMESPACES" default:"default"`
22
12
}
23
13
24
- func (c config ) logLevel () loggo.Level {
14
+ func getRootConfig () (* rootConfig , error ) {
15
+ ret := new (rootConfig )
16
+ if err := config .Load (ret ); err != nil {
17
+ return nil , err
18
+ }
19
+ return ret , nil
20
+ }
21
+
22
+ func (c rootConfig ) logLevel () loggo.Level {
25
23
switch c .LogLevel {
26
24
case "trace" :
27
25
return loggo .TRACE
@@ -39,11 +37,3 @@ func (c config) logLevel() loggo.Level {
39
37
return loggo .INFO
40
38
}
41
39
}
42
-
43
- func getConfig (appName string ) (* config , error ) {
44
- spec := new (config )
45
- if err := envconfig .Process (appName , spec ); err != nil {
46
- return nil , err
47
- }
48
- return spec , nil
49
- }
Original file line number Diff line number Diff line change
1
+ package config
2
+
3
+ import (
4
+ "github.com/kelseyhightower/envconfig"
5
+ )
6
+
7
+ const (
8
+ // AppName is the standard app name to use in fetching configs
9
+ AppName = "steward"
10
+ )
11
+
12
+ // Load is a convenience function for calling envconfig.Process(AppName, ret) (godoc.org/github.com/kelseyhightower/envconfig#Process)
13
+ func Load (ret interface {}) error {
14
+ return envconfig .Process (AppName , ret )
15
+ }
Original file line number Diff line number Diff line change @@ -9,10 +9,6 @@ import (
9
9
"github.com/juju/loggo"
10
10
)
11
11
12
- const (
13
- appName = "steward"
14
- )
15
-
16
12
var (
17
13
logger = loggo .GetLogger ("" )
18
14
version = "dev"
@@ -25,7 +21,7 @@ func exitWithCode(cancelFn func(), exitCode int) {
25
21
26
22
func main () {
27
23
logger .Infof ("steward version %s started" , version )
28
- cfg , err := getConfig ( appName )
24
+ cfg , err := getRootConfig ( )
29
25
if err != nil {
30
26
logger .Criticalf ("error getting config (%s)" , err )
31
27
os .Exit (1 )
Original file line number Diff line number Diff line change 1
1
package utils
2
2
3
3
import (
4
+ "github.com/deis/steward/config"
4
5
"github.com/deis/steward/web"
5
- "github.com/kelseyhightower/envconfig"
6
6
)
7
7
8
8
type cfConfig struct {
@@ -15,7 +15,7 @@ type cfConfig struct {
15
15
16
16
func getCfConfig () (* cfConfig , error ) {
17
17
ret := new (cfConfig )
18
- if err := envconfig . Process ( appName , ret ); err != nil {
18
+ if err := config . Load ( ret ); err != nil {
19
19
return nil , err
20
20
}
21
21
return ret , nil
Original file line number Diff line number Diff line change @@ -4,10 +4,6 @@ import (
4
4
"github.com/juju/loggo"
5
5
)
6
6
7
- const (
8
- appName = "steward"
9
- )
10
-
11
7
var (
12
8
logger = loggo .GetLogger ("mode.utils" )
13
9
)
You can’t perform that action at this time.
0 commit comments