package utils import ( "fmt" "math/rand" "strconv" "time" ) func GenCustomerIdentifier() string { random := rand.New(rand.NewSource(time.Now().UnixNano())) return fmt.Sprintf("%08v", random.Int31n(100000000)) } // 生成随机字符串 func GenerateSubString() string { var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") var n = 12 b := make([]rune, n) for i := range b { b[i] = letterRunes[rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(letterRunes))] } return string(b) } func Interface2String(inter interface{}) string { switch inter.(type) { case string: return inter.(string) case int: return strconv.Itoa(inter.(int)) case int64: return strconv.FormatInt(inter.(int64), 10) case float64: return strconv.FormatFloat(inter.(float64), 'f', -1, 64) case bool: return strconv.FormatBool(inter.(bool)) } return "" }