Codebase list zonedb / 482959a
internal/build: add Zone.Language string for BCP 47 language tag Randy Reddig 3 years ago
1 changed file(s) with 16 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
77 "unicode/utf8"
88
99 "golang.org/x/net/idna"
10 "golang.org/x/text/language"
1011 )
1112
1213 // Zone represents a build-time DNS zone (public suffix).
1314 type Zone struct {
1415 Domain string `json:"domain,omitempty"`
1516 InfoURL string `json:"infoURL,omitempty"`
17 Language string `json:"language,omitempty"`
1618 Tags []string `json:"tags,omitempty"`
1719 Locations []string `json:"locations,omitempty"`
1820 WhoisServer string `json:"whoisServer,omitempty"`
3638 func (z *Zone) Normalize() {
3739 z.Domain = Normalize(z.Domain)
3840 z.InfoURL = NormalizeURL(z.InfoURL)
41 z.normalizeLanguage()
3942 var tags []string
4043 tags = append(tags, z.Tags...)
4144 z.Tags = NewSet(tags...).Values()
4548 z.WhoisServer = Normalize(z.WhoisServer)
4649 z.WhoisURL = NormalizeURL(z.WhoisURL)
4750 z.normalizePolicies()
51 }
52
53 func (z *Zone) normalizeLanguage() {
54 if z.Language == "" {
55 return
56 }
57 tag, err := language.Parse(z.Language)
58 if err != nil {
59 Trace("Zone %s has malformed language tag: %s\n", z.Domain, z.Language)
60 z.Language = ""
61 } else {
62 z.Language = tag.String()
63 }
4864 }
4965
5066 func (z *Zone) normalizePolicies() {