package util import ( "math/rand" "strconv" "time" ) func StringToInt(id string) int { if id != "" { id, err := strconv.Atoi(id) if err == nil { return id } } return -1 } func RandomString(n int) string { var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") rand.Seed(time.Now().Unix()) b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) } func RandomString2(n int) string { var letters = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") rand.Seed(time.Now().Unix()) b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) }