chore: Create a resolver package
This commit is contained in:
parent
a57814688c
commit
b602beda0f
8 changed files with 63 additions and 33 deletions
|
@ -67,6 +67,12 @@ func main() {
|
|||
Usage: "Network class of the DNS record to be queried (IN, CH, HS etc)",
|
||||
Destination: qFlags.QClasses,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "https",
|
||||
Usage: "Use the DNS-over-HTTPS protocol",
|
||||
Destination: &qFlags.IsDOH,
|
||||
DefaultText: "udp",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "verbose",
|
||||
Usage: "Enable verbose logging",
|
||||
|
|
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/miekg/dns"
|
||||
"github.com/mr-karan/doggo/pkg/resolve"
|
||||
"github.com/mr-karan/doggo/pkg/resolvers"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
@ -13,7 +13,7 @@ type Hub struct {
|
|||
Version string
|
||||
QueryFlags QueryFlags
|
||||
Questions []dns.Question
|
||||
Resolver *resolve.Resolver
|
||||
Resolver resolvers.Resolver
|
||||
}
|
||||
|
||||
// QueryFlags is used store the value of CLI flags.
|
||||
|
@ -22,6 +22,10 @@ type QueryFlags struct {
|
|||
QTypes *cli.StringSlice
|
||||
QClasses *cli.StringSlice
|
||||
Nameservers *cli.StringSlice
|
||||
IsDOH bool
|
||||
IsDOT bool
|
||||
IsUDP bool
|
||||
IsTLS bool
|
||||
}
|
||||
|
||||
// NewHub initializes an instance of Hub which holds app wide configuration.
|
||||
|
|
21
cmd/parse.go
21
cmd/parse.go
|
@ -1,11 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/mr-karan/doggo/pkg/resolve"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -55,22 +53,3 @@ func (hub *Hub) loadFallbacks(c *cli.Context) {
|
|||
hub.QueryFlags.QClasses.Set("IN")
|
||||
}
|
||||
}
|
||||
|
||||
// loadResolver checks
|
||||
func (hub *Hub) loadResolver(c *cli.Context) error {
|
||||
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 := resolve.NewResolverFromResolvFile(resolve.DefaultResolvConfPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hub.Resolver = rslvr
|
||||
}
|
||||
} else {
|
||||
rslvr := resolve.NewResolver(hub.QueryFlags.Nameservers.Value())
|
||||
hub.Resolver = rslvr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
27
cmd/resolver.go
Normal file
27
cmd/resolver.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
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 {
|
||||
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
|
||||
}
|
||||
} else {
|
||||
rslvr := resolvers.NewResolver(hub.QueryFlags.Nameservers.Value())
|
||||
hub.Resolver = rslvr
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue