Skip to content

Commit

Permalink
Add support for a nested config
Browse files Browse the repository at this point in the history
  • Loading branch information
donny-dont committed Jun 26, 2020
1 parent cacc23c commit 29d49d4
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions stow.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,14 @@ type Config interface {
// Config gets a string configuration value and a
// bool indicating whether the value was present or not.
Config(name string) (string, bool)
// NestedConfig gets a key/value configuration and a
// bool indicating whehter the value was present or not.
NestedConfig(name string) (Config, bool)
// Set sets the configuration name to specified value
Set(name, value string)
// SetNestedConfig sets the configuration name to the
// specified key/value configuration.
SetNestedConfig(name string, value Config)
}

// Register adds a Location implementation, with two helper functions.
Expand Down Expand Up @@ -221,12 +227,19 @@ func KindByURL(u *url.URL) (string, error) {

// ConfigMap is a map[string]string that implements
// the Config method.
type ConfigMap map[string]string
type ConfigMap map[string]interface{}

// Config gets a string configuration value and a
// bool indicating whether the value was present or not.
func (c ConfigMap) Config(name string) (string, bool) {
val, ok := c[name]
val, ok := c[name].(string)
return val, ok
}

// NestedConfig gets a key/value configuration and a
// bool indicating whehter the value was present or not.
func (c ConfigMap) NestedConfig(name string) (Config, bool) {
val, ok := c[name].(Config)
return val, ok
}

Expand All @@ -235,6 +248,12 @@ func (c ConfigMap) Set(name, value string) {
c[name] = value
}

// SetNestedConfig sets the configuration name to the
// specified key/value configuration.
func (c ConfigMap) SetNestedConfig(name string, value Config) {
c[name] = value
}

// errUnknownKind indicates that a kind is unknown.
type errUnknownKind string

Expand Down

0 comments on commit 29d49d4

Please sign in to comment.