Fix go idiom feedback

This commit is contained in:
Tim Hockin
2014-07-11 11:22:22 -07:00
parent 56735fe2ec
commit 7d5398bda7
2 changed files with 46 additions and 84 deletions

View File

@@ -85,14 +85,14 @@ const (
// SetYAML implements the yaml.Setter interface.
func (intstr *IntOrString) SetYAML(tag string, value interface{}) bool {
if intVal, ok := value.(int); ok {
switch v := value.(type) {
case int:
intstr.Kind = IntstrInt
intstr.IntVal = intVal
intstr.IntVal = v
return true
}
if strVal, ok := value.(string); ok {
case string:
intstr.Kind = IntstrString
intstr.StrVal = strVal
intstr.StrVal = v
return true
}
return false
@@ -129,6 +129,6 @@ func (intstr IntOrString) MarshalJSON() ([]byte, error) {
case IntstrString:
return json.Marshal(intstr.StrVal)
default:
panic("impossible IntOrString.Kind")
return []byte{}, fmt.Errorf("impossible IntOrString.Kind")
}
}