utils.go 763 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package utils
  2. import (
  3. "gd_management_gateway/errors"
  4. "encoding/json"
  5. "fmt"
  6. "time"
  7. "unicode"
  8. )
  9. func GetUniqueLogID(cmd string) string {
  10. return fmt.Sprintf("%d_%s", time.Now().Unix(), cmd)
  11. }
  12. // 获取args对应的json字符串
  13. func MarshalJsonString(args ...interface{}) (result string) {
  14. if len(args) > 0 {
  15. if r, err := json.Marshal(args); err == nil {
  16. result = string(r)
  17. }
  18. }
  19. return
  20. }
  21. func VerifyPassword(pwd string) error {
  22. if len(pwd) < 8 {
  23. return errors.PasswordError
  24. }
  25. var (
  26. hasNumber bool
  27. hasLetter bool
  28. )
  29. for _, v := range pwd {
  30. switch {
  31. case unicode.IsNumber(v):
  32. hasNumber = true
  33. case unicode.IsLetter(v):
  34. hasLetter = true
  35. }
  36. }
  37. if !hasNumber || !hasLetter {
  38. return errors.PasswordError
  39. }
  40. return nil
  41. }