diff options
Diffstat (limited to 'config/lookup.go')
| -rw-r--r-- | config/lookup.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/config/lookup.go b/config/lookup.go new file mode 100644 index 00000000..1f3c03fe --- /dev/null +++ b/config/lookup.go @@ -0,0 +1,45 @@ +package config + +import "strings" + +// Lookup retrieves the first value for a given section, optional subsection, +// and key. +func (c *Config) Lookup(section, subsection, key string) LookupResult { + section = strings.ToLower(section) + + key = strings.ToLower(key) + for _, entry := range c.entries { + if strings.EqualFold(entry.Section, section) && + entry.Subsection == subsection && + strings.EqualFold(entry.Key, key) { + return LookupResult{ + Kind: entry.Kind, + Value: entry.Value, + } + } + } + + return LookupResult{Kind: ValueMissing} +} + +// LookupAll retrieves all values for a given section, optional subsection, +// and key. +func (c *Config) LookupAll(section, subsection, key string) []LookupResult { + section = strings.ToLower(section) + key = strings.ToLower(key) + + var values []LookupResult + + for _, entry := range c.entries { + if strings.EqualFold(entry.Section, section) && + entry.Subsection == subsection && + strings.EqualFold(entry.Key, key) { + values = append(values, LookupResult{ + Kind: entry.Kind, + Value: entry.Value, + }) + } + } + + return values +} |
