Created
June 1, 2020 11:47
-
-
Save unwosu/b623c32d08717d0cce8546dde5a90d93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func populate(v reflect.Value, value string) error { | |
switch v.Kind() { | |
case reflect.String: | |
v.SetString(value) | |
case reflect.Int: | |
i, err := strconv.ParseInt(value, 10, 64) | |
if err != nil { | |
return err | |
} | |
v.SetInt(i) | |
case reflect.Bool: | |
b, err := strconv.ParseBool(value) | |
if err != nil { | |
return err | |
} | |
v.SetBool(b) | |
default: | |
return fmt.Errorf("unsupported king %s", v.Type()) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment