photoprism/pkg/http/dns/label.go
Michael Mayer a921f82a17 Pkg: Move /service/http/... to /http/... and add package /http/dns
Signed-off-by: Michael Mayer <michael@photoprism.app>
2025-10-19 21:08:48 +02:00

16 lines
348 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package dns
import (
"regexp"
)
var labelRegex = regexp.MustCompile(`^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$`)
// IsLabel returns true if s is a valid DNS label per our rules: lowercase, [a-z0-9-], 132 chars, starts/ends alnum.
func IsLabel(s string) bool {
if s == "" || len(s) > 32 {
return false
}
return labelRegex.MatchString(s)
}