func (tx *btx) _findNCValue(ncv *ncdomain.Value, isubname, subname string, depth int, shortCircuitFunc func(curNCV *ncdomain.Value) bool) (xncv *ncdomain.Value, sn string, err error) { if shortCircuitFunc != nil && shortCircuitFunc(ncv) { return ncv, subname, nil } if isubname != "" { head, rest := util.SplitDomainHead(isubname) sub, ok := ncv.Map[head] if !ok { sub, ok = ncv.Map["*"] if !ok { return nil, "", merr.ErrNoSuchDomain } } return tx._findNCValue(sub, rest, head+"."+subname, depth+1, shortCircuitFunc) } if shortCircuitFunc != nil { return nil, subname, merr.ErrNoSuchDomain } return ncv, subname, nil }
func (v *Value) findSubdomainByName(subdomain string) (*Value, error) { if subdomain == "" { return v, nil } if strings.HasSuffix(subdomain, ".") { return nil, fmt.Errorf("a subdomain name should not be fully qualified") } head, rest := util.SplitDomainHead(subdomain) if sub, ok := v.Map[head]; ok { return sub.findSubdomainByName(rest) } return nil, fmt.Errorf("subdomain part not found: %s", head) }
func TestSplitDomainHead(t *testing.T) { for i := range items { head, rest := util.SplitDomainHead(items[i].input) tail, trest := util.SplitDomainTail(items[i].input) if head != items[i].expectedHead { t.Errorf("Input \"%s\": head \"%s\" does not equal expected value \"%s\"", items[i].input, head, items[i].expectedHead) } if rest != items[i].expectedRest { t.Errorf("Input \"%s\": rest \"%s\" does not equal expected value \"%s\"", items[i].input, rest, items[i].expectedRest) } if tail != items[i].expectedTail { t.Errorf("Input \"%s\": tail \"%s\" does not equal expected value \"%s\"", items[i].input, tail, items[i].expectedTail) } if trest != items[i].expectedTailRest { t.Errorf("Input \"%s\": tail rest \"%s\" does not equal expected value \"%s\"", items[i].input, trest, items[i].expectedTailRest) } } }