Sam Therapy
1b5d5a3fed
Some checks failed
continuous-integration/drone/push Build is failing
Signed-off-by: Sam Therapy <sam@samtherapy.net>
45 lines
983 B
Go
45 lines
983 B
Go
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package query
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"git.froth.zone/sam/awl/cli"
|
|
"git.froth.zone/sam/awl/internal/structs"
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
type Resolver interface {
|
|
LookUp(*dns.Msg) (structs.Response, error)
|
|
}
|
|
|
|
func LoadResolver(server string, opts cli.Options) (Resolver, error) {
|
|
switch {
|
|
case opts.HTTPS:
|
|
opts.Logger.Debug("loading DoH resolver")
|
|
if !strings.HasPrefix(server, "https://") {
|
|
server = "https://" + server
|
|
}
|
|
return &HTTPSResolver{
|
|
server: server,
|
|
opts: opts,
|
|
}, nil
|
|
case opts.QUIC:
|
|
opts.Logger.Debug("loading DoQ resolver")
|
|
server = net.JoinHostPort(opts.Request.Server, strconv.Itoa(opts.Port))
|
|
return &QUICResolver{
|
|
server: server,
|
|
opts: opts,
|
|
}, nil
|
|
default:
|
|
opts.Logger.Debug("loading standard/DoT resolver")
|
|
server = net.JoinHostPort(opts.Request.Server, strconv.Itoa(opts.Port))
|
|
return &StandardResolver{
|
|
server: server,
|
|
opts: opts,
|
|
}, nil
|
|
}
|
|
}
|