Skip to content

Commit

Permalink
expand slice on passing
Browse files Browse the repository at this point in the history
  • Loading branch information
zoli committed Aug 4, 2016
1 parent 3749fa7 commit 6377287
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (s *Settings) Get(name string, def ...interface{}) interface{} {
}

func (s *Settings) Int(name string, def ...interface{}) int {
value := s.Get(name, def)
value := s.Get(name, def...)
switch val := value.(type) {
case int64:
return int(val)
Expand All @@ -156,34 +156,21 @@ func (s *Settings) Int(name string, def ...interface{}) int {
case float64:
return int(val)
}
if len(def) > 0 {
if v, k := def[0].(int); k {
return v
}
}
panic(fmt.Sprintf("value of %s cannot be represented as an int: %#v", name, value))
}

func (s *Settings) String(name string, def ...interface{}) string {
value, ok := s.Get(name, def).(string)
value, ok := s.Get(name, def...).(string)
if ok {
return value
} else if len(def) > 0 {
if v, k := def[0].(string); k {
return v
}
}
panic(fmt.Sprintf("value of %s cannot be represented as an string: %#v", name, value))
}

func (s *Settings) Bool(name string, def ...interface{}) bool {
value, ok := s.Get(name, def).(bool)
value, ok := s.Get(name, def...).(bool)
if ok {
return value
} else if len(def) > 0 {
if v, k := def[0].(bool); k {
return v
}
}
panic(fmt.Sprintf("value of %s cannot be represented as an bool: %#v", name, value))
}
Expand Down

0 comments on commit 6377287

Please sign in to comment.