awl/query/resolver.go
Sam Therapy 92812c337f
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Another day's work
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-07-21 19:06:46 -05:00

46 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/helpers"
"github.com/miekg/dns"
)
type Resolver interface {
LookUp(*dns.Msg) (helpers.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
}
}