awl/query/resolver.go
Sam Therapy 1b5d5a3fed
Some checks failed
continuous-integration/drone/push Build is failing
Do "a few things"
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-07-20 23:14:15 +02:00

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
}
}