diff options
Diffstat (limited to 'dns/proxy.go')
-rw-r--r-- | dns/proxy.go | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/dns/proxy.go b/dns/proxy.go index ad81c6d..5ea23ed 100644 --- a/dns/proxy.go +++ b/dns/proxy.go @@ -36,7 +36,7 @@ type Handler func(*Request) *Reply // Proxy represents a DNS proxy. type Proxy struct { - handler Handler + Handler Handler resolvers []string cache *cache.Cache logger logger @@ -47,14 +47,10 @@ type Proxy struct { // ProxyOptions represents proxy configuration. type ProxyOptions struct { - Handler Handler - Resolvers []string - Logger logger - LogMode int - Network string - Timeout time.Duration - CacheSize int - CacheExpiryInterval time.Duration + Resolvers []string + LogMode int + Network string + Timeout time.Duration } type client interface { @@ -68,17 +64,12 @@ type logger interface { } // NewProxy creates a new DNS proxy. -func NewProxy(options ProxyOptions) (*Proxy, error) { - cache, err := cache.New(options.CacheSize, options.CacheExpiryInterval) - if err != nil { - return nil, err - } +func NewProxy(cache *cache.Cache, logger logger, options ProxyOptions) (*Proxy, error) { return &Proxy{ - handler: options.Handler, + logger: logger, + cache: cache, resolvers: options.Resolvers, - logger: options.Logger, logMode: options.LogMode, - cache: cache, client: &dns.Client{Net: options.Network, Timeout: options.Timeout}, }, nil } @@ -119,10 +110,10 @@ func (r *Reply) String() string { } func (p *Proxy) reply(r *dns.Msg) *dns.Msg { - if p.handler == nil || len(r.Question) != 1 { + if p.Handler == nil || len(r.Question) != 1 { return nil } - reply := p.handler(&Request{ + reply := p.Handler(&Request{ Name: r.Question[0].Name, Type: r.Question[0].Qtype, }) |