mcfg: always lowercase param and child names

This commit is contained in:
Brian Picciano 2018-08-13 11:50:57 -04:00
parent 0e9b7245be
commit 7861cf148e
2 changed files with 3 additions and 0 deletions

View File

@ -254,6 +254,7 @@ func (c *Cfg) StopRun(ctx context.Context) error {
// prepended to all configuration options created in the returned sub-Cfg, and // prepended to all configuration options created in the returned sub-Cfg, and
// must not be empty. // must not be empty.
func (c *Cfg) Child(name string) *Cfg { func (c *Cfg) Child(name string) *Cfg {
name = strings.ToLower(name)
if _, ok := c.Children[name]; ok { if _, ok := c.Children[name]; ok {
panic(fmt.Sprintf("child Cfg named %q already exists", name)) panic(fmt.Sprintf("child Cfg named %q already exists", name))
} }

View File

@ -2,6 +2,7 @@ package mcfg
import ( import (
"fmt" "fmt"
"strings"
"github.com/mediocregopher/mediocre-go-lib/mtime" "github.com/mediocregopher/mediocre-go-lib/mtime"
) )
@ -40,6 +41,7 @@ type Param struct {
// ParamAdd adds the given Param to the Cfg. It will panic if a Param of the // ParamAdd adds the given Param to the Cfg. It will panic if a Param of the
// same Name already exists in the Cfg. // same Name already exists in the Cfg.
func (c *Cfg) ParamAdd(p Param) { func (c *Cfg) ParamAdd(p Param) {
p.Name = strings.ToLower(p.Name)
if _, ok := c.Params[p.Name]; ok { if _, ok := c.Params[p.Name]; ok {
panic(fmt.Sprintf("Cfg.Path:%#v name:%q already exists", c.Path, p.Name)) panic(fmt.Sprintf("Cfg.Path:%#v name:%q already exists", c.Path, p.Name))
} }