Skip to content

Instantly share code, notes, and snippets.

@shicky
Created July 15, 2016 10:35
Show Gist options
  • Save shicky/acf34160c4767725bded6797fba17575 to your computer and use it in GitHub Desktop.
Save shicky/acf34160c4767725bded6797fba17575 to your computer and use it in GitHub Desktop.
Convert reflect.Value to appropriate variable
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