1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-06 06:30:18 +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

@ -269,10 +269,11 @@ func (c *IniConfigContainer) DefaultString(key string, defaultval string) string
}
// Strings returns the []string value for a given key.
// Return nil if config value does not exist or is empty.
func (c *IniConfigContainer) Strings(key string) []string {
v := c.String(key)
if v == "" {
return []string{}
return nil
}
return strings.Split(v, ";")
}
@ -281,7 +282,7 @@ func (c *IniConfigContainer) Strings(key string) []string {
// if err != nil return defaltval
func (c *IniConfigContainer) DefaultStrings(key string, defaultval []string) []string {
v := c.Strings(key)
if len(v) == 0 {
if v == nil {
return defaultval
}
return v