mcfg: always lowercase param and child names
This commit is contained in:
parent
0e9b7245be
commit
7861cf148e
@ -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))
|
||||||
}
|
}
|
||||||
|
@ -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))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user