common.go 448 B

123456789101112131415161718192021222324252627
  1. package util
  2. import (
  3. "math/rand"
  4. "strconv"
  5. "time"
  6. )
  7. func StringToInt(id string) int {
  8. if id != "" {
  9. id, err := strconv.Atoi(id)
  10. if err == nil {
  11. return id
  12. }
  13. }
  14. return -1
  15. }
  16. func RandomString(n int) string {
  17. var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
  18. rand.Seed(time.Now().Unix())
  19. b := make([]rune, n)
  20. for i := range b {
  21. b[i] = letters[rand.Intn(len(letters))]
  22. }
  23. return string(b)
  24. }