awl/query/resolver.go
Sam Therapy eda2e5b55f
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
More work!
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-07-22 23:22:43 +02:00

50 lines
1.2 KiB
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(opts cli.Options) (Resolver, error) {
switch {
case opts.HTTPS:
opts.Logger.Info("loading DNS-over-HTTPS resolver")
if !strings.HasPrefix(opts.Request.Server, "https://") {
opts.Request.Server = "https://" + opts.Request.Server
}
return &HTTPSResolver{
opts: opts,
}, nil
case opts.QUIC:
opts.Logger.Info("loading DNS-over-QUIC resolver")
opts.Request.Server = net.JoinHostPort(opts.Request.Server, strconv.Itoa(opts.Port))
return &QUICResolver{
opts: opts,
}, nil
case opts.DNSCrypt:
opts.Logger.Info("loading DNSCrypt resolver")
if !strings.HasPrefix(opts.Request.Server, "sdns://") {
opts.Request.Server = "sdns://" + opts.Request.Server
}
return &DNSCryptResolver{
opts: opts,
}, nil
default:
opts.Logger.Info("loading standard/DNS-over-TLS resolver")
opts.Request.Server = net.JoinHostPort(opts.Request.Server, strconv.Itoa(opts.Port))
return &StandardResolver{
opts: opts,
}, nil
}
}