Created
July 15, 2016 10:35
-
-
Save shicky/acf34160c4767725bded6797fba17575 to your computer and use it in GitHub Desktop.
Convert reflect.Value to appropriate variable
This file contains hidden or 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
package gocelery | |
import ( | |
"reflect" | |
"strconv" | |
) | |
// GetRealValue returns real value of reflect.Value | |
func GetRealValue(val reflect.Value) interface{} { | |
switch val.Kind() { | |
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: | |
return strconv.FormatInt(val.Int(), 10) | |
case reflect.String: | |
return val.String() | |
case reflect.Bool: | |
return val.Bool() | |
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: | |
return strconv.FormatUint(val.Uint(), 10) | |
case reflect.Float32, reflect.Float64: | |
return val.Float() | |
default: | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment