package lib import ( "encoding/json" "fmt" "strconv" "sync" ) type Cl_ struct { Uuid_list map[string]string // 泛型 } var SubClinets sync.Map // 订阅Map func init() { } func To_float32(value interface{}) float32 { var key float32 if value == nil { return key } switch value.(type) { case float64: key = float32(value.(float64)) case float32: key = float32(value.(float32)) case int: key = float32(value.(int)) case uint: key = float32(value.(uint)) case int8: key = float32(value.(int8)) case uint8: key = float32(value.(uint8)) case int16: key = float32(value.(int16)) case uint16: key = float32(value.(uint16)) case int32: key = float32(value.(int32)) case uint32: key = float32(value.(uint32)) case int64: key = float32(value.(int64)) case uint64: key = float32(value.(uint64)) case string: key_float64, _ := strconv.ParseFloat(value.(string), 32/64) key = float32(key_float64) case []byte: key_float64, _ := strconv.ParseFloat(string(value.([]byte)), 32/64) key = float32(key_float64) default: newValue, _ := json.Marshal(value) key_float64, _ := strconv.ParseFloat(string(newValue), 32/64) key = float32(key_float64) } key_float64, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", key), 32/64) key = float32(key_float64) 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 }