mirror of
https://github.com/astaxie/beego.git
synced 2024-07-02 14:34:14 +00:00
21 lines
400 B
Go
21 lines
400 B
Go
package pagination
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
// convert any numeric value to int64
|
|
func ToInt64(value interface{}) (d int64, err error) {
|
|
val := reflect.ValueOf(value)
|
|
switch value.(type) {
|
|
case int, int8, int16, int32, int64:
|
|
d = val.Int()
|
|
case uint, uint8, uint16, uint32, uint64:
|
|
d = int64(val.Uint())
|
|
default:
|
|
err = fmt.Errorf("ToInt64 need numeric not `%T`", value)
|
|
}
|
|
return
|
|
}
|