123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package lib
- import (
- "encoding/json"
- "github.com/nats-io/nats.go"
- "github.com/thinkeridea/go-extend/exunicode/exutf8"
- "runtime"
- "strconv"
- "unicode/utf8"
- )
- var Nats *nats.Conn
- func To_int64(value interface{}) int64 {
- var key int64
- if value == nil {
- return key
- }
- switch value.(type) {
- case float64:
- key = int64(value.(float64))
- case float32:
- key = int64(value.(float32))
- case int:
- key = int64(value.(int))
- case uint:
- key = int64(value.(uint))
- case int8:
- key = int64(value.(int8))
- case uint8:
- key = int64(value.(uint8))
- case int16:
- key = int64(value.(int16))
- case uint16:
- key = int64(value.(uint16))
- case int32:
- key = int64(value.(int32))
- case uint32:
- key = int64(value.(uint32))
- case int64:
- key = int64(value.(int64))
- case uint64:
- key = int64(value.(uint64))
- case string:
- key, _ = strconv.ParseInt(value.(string), 10, 64)
- case []byte:
- key, _ = strconv.ParseInt(string(value.([]byte)), 10, 64)
- default:
- newValue, _ := json.Marshal(value)
- key, _ = strconv.ParseInt(string(newValue), 10, 64)
- }
- return key
- }
- func To_string(value interface{}) string {
- var key string
- if value == nil {
- return key
- }
- switch value.(type) {
- case float64:
- ft := value.(float64)
- key = strconv.FormatFloat(ft, 'f', -1, 64)
- case float32:
- ft := value.(float32)
- key = strconv.FormatFloat(float64(ft), 'f', -1, 64)
- case int:
- it := value.(int)
- key = strconv.Itoa(it)
- case uint:
- it := value.(uint)
- key = strconv.Itoa(int(it))
- case int8:
- it := value.(int8)
- key = strconv.Itoa(int(it))
- case uint8:
- it := value.(uint8)
- key = strconv.Itoa(int(it))
- case int16:
- it := value.(int16)
- key = strconv.Itoa(int(it))
- case uint16:
- it := value.(uint16)
- key = strconv.Itoa(int(it))
- case int32:
- it := value.(int32)
- key = strconv.Itoa(int(it))
- case uint32:
- it := value.(uint32)
- key = strconv.Itoa(int(it))
- case int64:
- it := value.(int64)
- key = strconv.FormatInt(it, 10)
- case uint64:
- it := value.(uint64)
- key = strconv.FormatUint(it, 10)
- case string:
- key = value.(string)
- case []byte:
- key = string(value.([]byte))
- default:
- newValue, _ := json.Marshal(value)
- key = string(newValue)
- }
- return key
- }
- // 获取正在运行的函数名
- func FuncName() string {
- pc := make([]uintptr, 1)
- runtime.Callers(2, pc)
- f := runtime.FuncForPC(pc[0])
- return f.Name()
- }
- func Limit_len(str string,lenx int) string {
- if utf8.RuneCountInString(str) > lenx {
- return exutf8.RuneSubString(str, 0, lenx-3)+"..."
- }
- return exutf8.RuneSubString(str, 0, lenx)
- }
|