2022-02-03 15:32:03 +08:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2022-08-20 21:03:15 +08:00
|
|
|
"net/mail"
|
2022-02-03 15:32:03 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HasPrefixes returns true if the string s has any of the given prefixes.
|
|
|
|
func HasPrefixes(src string, prefixes ...string) bool {
|
|
|
|
for _, prefix := range prefixes {
|
|
|
|
if strings.HasPrefix(src, prefix) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-08-20 21:03:15 +08:00
|
|
|
// ValidateEmail validates the email.
|
|
|
|
func ValidateEmail(email string) bool {
|
|
|
|
if _, err := mail.ParseAddress(email); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-02-03 15:32:03 +08:00
|
|
|
func GenUUID() string {
|
|
|
|
return uuid.New().String()
|
|
|
|
}
|
2022-10-27 22:02:42 +08:00
|
|
|
|
|
|
|
func Min(x, y int) int {
|
|
|
|
if x < y {
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
return y
|
|
|
|
}
|