mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 08:50:56 +00:00
Update templatefunc.go
This commit is contained in:
parent
d4e15c0bd0
commit
d91840779a
@ -698,29 +698,36 @@ func MapGet(arg1 interface{}, arg2 ...interface{}) (interface{}, error) {
|
|||||||
|
|
||||||
storedVal := arg1Val.MapIndex(arg2Val)
|
storedVal := arg1Val.MapIndex(arg2Val)
|
||||||
|
|
||||||
var result interface{}
|
|
||||||
|
if storedVal.IsValid() {
|
||||||
|
var result interface{}
|
||||||
|
|
||||||
switch arg1Type.Elem().Kind() {
|
switch arg1Type.Elem().Kind() {
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
result = storedVal.Bool()
|
result = storedVal.Bool()
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
result = storedVal.Int()
|
result = storedVal.Int()
|
||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||||
result = storedVal.Uint()
|
result = storedVal.Uint()
|
||||||
case reflect.Float32, reflect.Float64:
|
case reflect.Float32, reflect.Float64:
|
||||||
result = storedVal.Float()
|
result = storedVal.Float()
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
result = storedVal.String()
|
result = storedVal.String()
|
||||||
default:
|
default:
|
||||||
result = storedVal.Interface()
|
result = storedVal.Interface()
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there is more keys, handle this recursively
|
// if there is more keys, handle this recursively
|
||||||
if len(arg2) > 1 {
|
if len(arg2) > 1 {
|
||||||
return MapGet(result, arg2[1:]...)
|
return MapGet(result, arg2[1:]...)
|
||||||
|
} else {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return result, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user