123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package util
- import (
- "math/rand"
- "strconv"
- "strings"
- "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)
- }
- func StringToIntArray(str string) []int64 {
- tmp := strings.Split(str, ",")
- var result []int64
- for _, t := range tmp {
- i, _ := strconv.ParseInt(t, 10, 64)
- result = append(result, i)
- }
- return result
- }
|