doggo/cmd/resolver.go

47 lines
1.1 KiB
Go

package main
import (
"runtime"
"github.com/mr-karan/doggo/pkg/resolvers"
)
// initResolver checks for various flags and initialises
// the correct resolver based on the config.
func (hub *Hub) initResolver() error {
// check if DOH flag is set.
if hub.QueryFlags.IsDOH {
rslvr, err := resolvers.NewDOHResolver(hub.QueryFlags.Nameservers)
if err != nil {
return err
}
hub.Resolver = rslvr
return nil
}
if len(hub.QueryFlags.Nameservers) == 0 {
if runtime.GOOS == "windows" {
// TODO: Add a method for reading system default nameserver in windows.
} else {
rslvr, err := resolvers.NewSystemResolver(resolvers.DefaultResolvConfPath)
if err != nil {
return err
}
hub.Resolver = rslvr
return nil
}
} else {
rslvr, err := resolvers.NewClassicResolver(hub.QueryFlags.Nameservers, resolvers.ClassicResolverOpts{
UseIPv4: hub.QueryFlags.UseIPv4,
UseIPv6: hub.QueryFlags.UseIPv6,
UseTLS: hub.QueryFlags.IsDOT,
UseTCP: hub.QueryFlags.UseTCP,
})
if err != nil {
return err
}
hub.Resolver = rslvr
return nil
}
return nil
}