mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	* Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * More lint fixes This leaves: ~~~ middleware/kubernetes/nametemplate/nametemplate.go:64:6: exported type NameTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:71:1: exported method NameTemplate.SetTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:108:1: exported method NameTemplate.GetZoneFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:116:1: exported method NameTemplate.GetNamespaceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:120:1: exported method NameTemplate.GetServiceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:124:1: exported method NameTemplate.GetTypeFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:135:1: exported method NameTemplate.GetSymbolFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:167:1: exported method NameTemplate.IsValid should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:182:6: exported type NameValues should have comment or be unexported middleware/kubernetes/util/util.go:1:1: package comment should be of the form "Package util ..." middleware/kubernetes/util/util.go:27:2: exported const WildcardStar should have comment (or a comment on this block) or be unexported middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported ~~~ I plan on reworking the proxy anyway, so I'll leave that be.
		
			
				
	
	
		
			119 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			119 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package tree
 | |
| 
 | |
| import "github.com/miekg/dns"
 | |
| 
 | |
| // Elem is an element in the tree.
 | |
| type Elem struct {
 | |
| 	m map[uint16][]dns.RR
 | |
| }
 | |
| 
 | |
| // newElem returns a new elem.
 | |
| func newElem(rr dns.RR) *Elem {
 | |
| 	e := Elem{m: make(map[uint16][]dns.RR)}
 | |
| 	e.m[rr.Header().Rrtype] = []dns.RR{rr}
 | |
| 	return &e
 | |
| }
 | |
| 
 | |
| // Types returns the RRs with type qtype from e.
 | |
| func (e *Elem) Types(qtype uint16) []dns.RR {
 | |
| 	if rrs, ok := e.m[qtype]; ok {
 | |
| 		return rrs
 | |
| 	}
 | |
| 	// nodata
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| // All returns all RRs from e, regardless of type.
 | |
| func (e *Elem) All() []dns.RR {
 | |
| 	list := []dns.RR{}
 | |
| 	for _, rrs := range e.m {
 | |
| 		list = append(list, rrs...)
 | |
| 	}
 | |
| 	return list
 | |
| }
 | |
| 
 | |
| // Name returns the name for this node.
 | |
| func (e *Elem) Name() string {
 | |
| 	for _, rrs := range e.m {
 | |
| 		return rrs[0].Header().Name
 | |
| 	}
 | |
| 	return ""
 | |
| }
 | |
| 
 | |
| // Insert inserts rr into e. If rr is equal to existing rrs this is a noop.
 | |
| func (e *Elem) Insert(rr dns.RR) {
 | |
| 	t := rr.Header().Rrtype
 | |
| 	if e.m == nil {
 | |
| 		e.m = make(map[uint16][]dns.RR)
 | |
| 		e.m[t] = []dns.RR{rr}
 | |
| 		return
 | |
| 	}
 | |
| 	rrs, ok := e.m[t]
 | |
| 	if !ok {
 | |
| 		e.m[t] = []dns.RR{rr}
 | |
| 		return
 | |
| 	}
 | |
| 	for _, er := range rrs {
 | |
| 		if equalRdata(er, rr) {
 | |
| 			return
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	rrs = append(rrs, rr)
 | |
| 	e.m[t] = rrs
 | |
| }
 | |
| 
 | |
| // Delete removes rr from e. When e is empty after the removal the returned bool is true.
 | |
| func (e *Elem) Delete(rr dns.RR) (empty bool) {
 | |
| 	if e.m == nil {
 | |
| 		return true
 | |
| 	}
 | |
| 
 | |
| 	t := rr.Header().Rrtype
 | |
| 	rrs, ok := e.m[t]
 | |
| 	if !ok {
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	for i, er := range rrs {
 | |
| 		if equalRdata(er, rr) {
 | |
| 			rrs = removeFromSlice(rrs, i)
 | |
| 			e.m[t] = rrs
 | |
| 			empty = len(rrs) == 0
 | |
| 			if empty {
 | |
| 				delete(e.m, t)
 | |
| 			}
 | |
| 			return
 | |
| 		}
 | |
| 	}
 | |
| 	return
 | |
| }
 | |
| 
 | |
| // Less is a tree helper function that calls less.
 | |
| func Less(a *Elem, name string) int { return less(name, a.Name()) }
 | |
| 
 | |
| // Assuming the same type and name this will check if the rdata is equal as well.
 | |
| func equalRdata(a, b dns.RR) bool {
 | |
| 	switch x := a.(type) {
 | |
| 	// TODO(miek): more types, i.e. all types. + tests for this.
 | |
| 	case *dns.A:
 | |
| 		return x.A.Equal(b.(*dns.A).A)
 | |
| 	case *dns.AAAA:
 | |
| 		return x.AAAA.Equal(b.(*dns.AAAA).AAAA)
 | |
| 	case *dns.MX:
 | |
| 		if x.Mx == b.(*dns.MX).Mx && x.Preference == b.(*dns.MX).Preference {
 | |
| 			return true
 | |
| 		}
 | |
| 	}
 | |
| 	return false
 | |
| }
 | |
| 
 | |
| // removeFromSlice removes index i from the slice.
 | |
| func removeFromSlice(rrs []dns.RR, i int) []dns.RR {
 | |
| 	if i >= len(rrs) {
 | |
| 		return rrs
 | |
| 	}
 | |
| 	rrs = append(rrs[:i], rrs[i+1:]...)
 | |
| 	return rrs
 | |
| }
 |