memos/common/util.go

38 lines
604 B
Go
Raw Normal View History

2022-02-03 10:32:03 +03:00
package common
import (
2022-08-20 16:03:15 +03:00
"net/mail"
2022-02-03 10:32:03 +03: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 16:03:15 +03:00
// ValidateEmail validates the email.
func ValidateEmail(email string) bool {
if _, err := mail.ParseAddress(email); err != nil {
return false
}
return true
}
2022-02-03 10:32:03 +03:00
func GenUUID() string {
return uuid.New().String()
}
2022-10-27 17:02:42 +03:00
func Min(x, y int) int {
if x < y {
return x
}
return y
}