diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-09-28 15:46:09 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-09-28 15:46:09 +0000 |
commit | 3cf936123cda48a8856fb6cd534331f2dabe9e15 (patch) | |
tree | c4b4754790e619082ca935cef0bb489f3a6470b6 /go/internal/config/config.go | |
parent | 1cc2993f357c4467e4d45c54c01d2307103efb3e (diff) | |
parent | f435c4644abc167cdfe6bfe3d320ff840f468c09 (diff) | |
download | gitlab-shell-3cf936123cda48a8856fb6cd534331f2dabe9e15.tar.gz |
Merge branch '74-go-go-go-go-go' into 'master'
Feature flag for go/ruby gitlab-shell implementations
Closes #74
See merge request gitlab-org/gitlab-shell!233
Diffstat (limited to 'go/internal/config/config.go')
-rw-r--r-- | go/internal/config/config.go | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/go/internal/config/config.go b/go/internal/config/config.go index 7d521f5..435cb29 100644 --- a/go/internal/config/config.go +++ b/go/internal/config/config.go @@ -13,31 +13,44 @@ const ( logFile = "gitlab-shell.log" ) +type MigrationConfig struct { + Enabled bool `yaml:"enabled"` + Features []string `yaml:"features"` +} + type Config struct { RootDir string - LogFile string `yaml:"log_file"` - LogFormat string `yaml:"log_format"` + LogFile string `yaml:"log_file"` + LogFormat string `yaml:"log_format"` + Migration MigrationConfig `yaml:"migration"` } func New() (*Config, error) { - cfg := Config{} - dir, err := os.Getwd() if err != nil { return nil, err } - cfg.RootDir = dir - configBytes, err := ioutil.ReadFile(path.Join(cfg.RootDir, configFile)) + return NewFromDir(dir) +} + +func NewFromDir(dir string) (*Config, error) { + return newFromFile(path.Join(dir, configFile)) +} + +func newFromFile(filename string) (*Config, error) { + cfg := &Config{RootDir: path.Dir(filename)} + + configBytes, err := ioutil.ReadFile(filename) if err != nil { return nil, err } - if err := parseConfig(configBytes, &cfg); err != nil { + if err := parseConfig(configBytes, cfg); err != nil { return nil, err } - return &cfg, nil + return cfg, nil } // parseConfig expects YAML data in configBytes and a Config instance with RootDir set. |