util.go 604 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package common
  2. import (
  3. "net/mail"
  4. "strings"
  5. "github.com/google/uuid"
  6. )
  7. // HasPrefixes returns true if the string s has any of the given prefixes.
  8. func HasPrefixes(src string, prefixes ...string) bool {
  9. for _, prefix := range prefixes {
  10. if strings.HasPrefix(src, prefix) {
  11. return true
  12. }
  13. }
  14. return false
  15. }
  16. // ValidateEmail validates the email.
  17. func ValidateEmail(email string) bool {
  18. if _, err := mail.ParseAddress(email); err != nil {
  19. return false
  20. }
  21. return true
  22. }
  23. func GenUUID() string {
  24. return uuid.New().String()
  25. }
  26. func Min(x, y int) int {
  27. if x < y {
  28. return x
  29. }
  30. return y
  31. }