1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-06 01:50:19 +00:00

Return nil not empty []string{}

Return nil if config value does not exist or is empty
This commit is contained in:
ysqi
2016-03-03 20:03:23 +08:00
parent 8ff74e71cb
commit 19d921d3f5
7 changed files with 17 additions and 12 deletions

View File

@ -173,7 +173,7 @@ func (c *JSONConfigContainer) DefaultString(key string, defaultval string) strin
func (c *JSONConfigContainer) Strings(key string) []string {
stringVal := c.String(key)
if stringVal == "" {
return []string{}
return nil
}
return strings.Split(c.String(key), ";")
}
@ -181,7 +181,7 @@ func (c *JSONConfigContainer) Strings(key string) []string {
// DefaultStrings returns the []string value for a given key.
// if err != nil return defaltval
func (c *JSONConfigContainer) DefaultStrings(key string, defaultval []string) []string {
if v := c.Strings(key); len(v) > 0 {
if v := c.Strings(key); v != nil {
return v
}
return defaultval