mirror of
https://github.com/coredns/coredns.git
synced 2025-11-15 00:12:16 -05:00
@@ -149,57 +149,3 @@ func parseTraffic(c *caddy.Controller) (*Traffic, error) {
|
||||
t.hosts = toHosts
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// parseLocality parses string s into loc's. Each loc must be space separated from the other, inside
|
||||
// a loc we have region,zone,subzone, where subzone or subzone and zone maybe empty. If specified
|
||||
// they must be comma separate (not spaces or anything).
|
||||
func parseLocality(s string) ([]xds.Locality, error) {
|
||||
sets := strings.Fields(s)
|
||||
if len(sets) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
locs := []xds.Locality{}
|
||||
for _, s := range sets {
|
||||
l := strings.Split(s, ",")
|
||||
switch len(l) {
|
||||
default:
|
||||
return nil, fmt.Errorf("too many location specifiers: %q", s)
|
||||
case 1:
|
||||
l0 := strings.TrimSpace(l[0])
|
||||
if l0 == "" {
|
||||
return nil, fmt.Errorf("empty location specifer: %q", l[0])
|
||||
}
|
||||
locs = append(locs, xds.Locality{Region: l0})
|
||||
continue
|
||||
case 2:
|
||||
l0 := strings.TrimSpace(l[0])
|
||||
if l0 == "" {
|
||||
return nil, fmt.Errorf("empty location specifer: %q", l[0])
|
||||
}
|
||||
l1 := strings.TrimSpace(l[1])
|
||||
if l1 == "" {
|
||||
return nil, fmt.Errorf("empty location specifer: %q", l[1])
|
||||
}
|
||||
locs = append(locs, xds.Locality{Region: l0, Zone: l1})
|
||||
continue
|
||||
case 3:
|
||||
l0 := strings.TrimSpace(l[0])
|
||||
if l0 == "" {
|
||||
return nil, fmt.Errorf("empty location specifer: %q", l[0])
|
||||
}
|
||||
l1 := strings.TrimSpace(l[1])
|
||||
if l1 == "" {
|
||||
return nil, fmt.Errorf("empty location specifer: %q", l[1])
|
||||
}
|
||||
l2 := strings.TrimSpace(l[2])
|
||||
if l2 == "" {
|
||||
return nil, fmt.Errorf("empty location specifer: %q", l[2])
|
||||
}
|
||||
locs = append(locs, xds.Locality{Region: l0, Zone: l1, SubZone: l2})
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
return locs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user