diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-06-08 17:28:40 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2019-06-08 17:28:40 +0200 |
commit | 6544d1d8ade6331c8c04f75439b13eec9b7fbe98 (patch) | |
tree | e6b9b9848b5936b8179b47e57f38e804d3637a9e /hosts/hosts.go | |
parent | 527e910184921230e0a97462b609b2880f045806 (diff) |
Add support for inline hosts
Diffstat (limited to 'hosts/hosts.go')
-rw-r--r-- | hosts/hosts.go | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/hosts/hosts.go b/hosts/hosts.go index 1a2c066..320b96f 100644 --- a/hosts/hosts.go +++ b/hosts/hosts.go @@ -92,36 +92,3 @@ func (p *Parser) Parse(r io.Reader) (Hosts, error) { } return entries, nil } - -// A Matcher matches hosts entries. -type Matcher struct { - hosts Hosts - next *Matcher -} - -// Match returns the IP addresses matching name. -func (m *Matcher) Match(name string) ([]net.IPAddr, bool) { - for m != nil { - if m.hosts != nil { - if ipAddrs, ok := m.hosts.Get(name); ok { - return ipAddrs, ok - } - } - m = m.next - } - return nil, false -} - -// NewMatcher creates a matcher for given hosts. -func NewMatcher(hosts ...Hosts) *Matcher { - matcher := &Matcher{} - m := matcher - for i, h := range hosts { - m.hosts = h - if i < len(hosts)-1 { - m.next = &Matcher{} - } - m = m.next - } - return matcher -} |