-
-
Save Developer1Dev/5ef4992014139aa0d0906c2f77e1d53b 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