awl/query/query.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

34 lines
800 B
Go

package query
import (
"git.froth.zone/sam/awl/cli"
"git.froth.zone/sam/awl/internal/structs"
"github.com/miekg/dns"
)
func CreateQuery(opts cli.Options) (structs.Response, error) {
var res structs.Response
res.DNS = new(dns.Msg)
res.DNS.SetQuestion(opts.Query, opts.Type)
res.DNS.MsgHdr.Response = opts.QR
res.DNS.MsgHdr.Authoritative = opts.AA
res.DNS.MsgHdr.Truncated = opts.TC
res.DNS.MsgHdr.RecursionDesired = opts.RD
res.DNS.MsgHdr.RecursionAvailable = opts.RA
res.DNS.MsgHdr.Zero = opts.Z
res.DNS.MsgHdr.AuthenticatedData = opts.AD
res.DNS.MsgHdr.CheckingDisabled = opts.CD
if opts.DNSSEC {
res.DNS.SetEdns0(1232, true)
}
resolver, err := LoadResolver(opts.Request.Server, opts)
if err != nil {
return structs.Response{}, err
}
return resolver.LookUp(res.DNS)
}