1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package utils
- import "time"
- func CostTime(start time.Time) int64 {
- duration := time.Now().UnixNano() - start.UnixNano()
- return duration / 1e6
- }
- type FeatureInfo struct {
- Value interface{} `json "value"`
- Type string `json "type"`
- }
- func ConvertFeatures(features map[string]interface{}) map[string]*FeatureInfo {
- ret := make(map[string]*FeatureInfo, len(features))
- for name, value := range features {
- info := &FeatureInfo{
- Value: value,
- Type: GetTypeOf(value),
- }
- ret[name] = info
- }
- return ret
- }
- func GetTypeOf(value interface{}) string {
- switch value.(type) {
- case int:
- return "int"
- case int32:
- return "int"
- case int64:
- return "bigint"
- case string:
- return "string"
- case float64:
- return "float64"
- default:
- return "none"
- }
- }
- func GetValueByType(value interface{}, vtype string) interface{} {
- switch vtype {
- case "int":
- return ToInt(value, 0)
- case "string":
- return ToString(value, "")
- case "float64":
- return ToFloat(value, float64(0))
- case "int64":
- return ToInt64(value, 0)
- case "bigint":
- return ToInt64(value, 0)
- default:
- return value
- }
- }
- func IndexOf(a []string, e string) int {
- n := len(a)
- var i = 0
- for ; i < n; i++ {
- if e == a[i] {
- return i
- }
- }
- return -1
- }
|