doggo/cmd/resolver.go

50 lines
1.1 KiB
Go
Raw Normal View History

2020-12-11 12:18:54 +01:00
package main
import (
"runtime"
"github.com/mr-karan/doggo/pkg/resolvers"
"github.com/urfave/cli/v2"
)
// loadResolver checks
func (hub *Hub) loadResolver(c *cli.Context) error {
2020-12-12 07:16:13 +01:00
// check if DOH flag is set.
if hub.QueryFlags.IsDOH {
rslvr, err := resolvers.NewDOHResolver(hub.QueryFlags.Nameservers.Value())
if err != nil {
return err
}
hub.Resolver = rslvr
return nil
}
// check if DOT flag is set.
// check if TCP flag is set.
// fallback to good ol UDP.
2020-12-11 12:18:54 +01:00
if len(hub.QueryFlags.Nameservers.Value()) == 0 {
if runtime.GOOS == "windows" {
// TODO: Add a method for reading system default nameserver in windows.
} else {
rslvr, err := resolvers.NewResolverFromResolvFile(resolvers.DefaultResolvConfPath)
if err != nil {
return err
}
hub.Resolver = rslvr
2020-12-12 07:16:13 +01:00
return nil
2020-12-11 12:18:54 +01:00
}
} else {
2020-12-12 07:46:54 +01:00
rslvr, err := resolvers.NewClassicResolver(hub.QueryFlags.Nameservers.Value(), resolvers.ClassicResolverOpts{
UseIPv4: hub.QueryFlags.UseIPv4,
UseIPv6: hub.QueryFlags.UseIPv6,
})
2020-12-12 07:16:13 +01:00
if err != nil {
return err
}
2020-12-11 12:18:54 +01:00
hub.Resolver = rslvr
2020-12-12 07:16:13 +01:00
return nil
2020-12-11 12:18:54 +01:00
}
return nil
}