style: format with go fmt
This commit is contained in:
parent
cedf03550f
commit
fcd18e5020
1 changed files with 39 additions and 28 deletions
47
stub.go
47
stub.go
|
|
@ -4,13 +4,13 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/caddyserver/caddy/v2"
|
||||||
|
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||||
|
"github.com/mholt/acmez"
|
||||||
|
"github.com/mholt/acmez/acme"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
"github.com/mholt/acmez"
|
|
||||||
"github.com/mholt/acmez/acme"
|
|
||||||
"github.com/caddyserver/caddy/v2"
|
|
||||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TTL of the challenge TXT record to serve
|
// TTL of the challenge TXT record to serve
|
||||||
|
|
@ -27,7 +27,6 @@ type StubDNS struct {
|
||||||
// Wrapper for logging (relevant parts of) dns.Msg
|
// Wrapper for logging (relevant parts of) dns.Msg
|
||||||
type LoggableDNSMsg struct{ *dns.Msg }
|
type LoggableDNSMsg struct{ *dns.Msg }
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy.RegisterModule(StubDNS{})
|
caddy.RegisterModule(StubDNS{})
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +58,6 @@ func (p *StubDNS) Provision(ctx caddy.Context) error {
|
||||||
// stub_dns [address] {
|
// stub_dns [address] {
|
||||||
// address <address>
|
// address <address>
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
func (s *StubDNS) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
func (s *StubDNS) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
for d.Next() {
|
for d.Next() {
|
||||||
if d.NextArg() {
|
if d.NextArg() {
|
||||||
|
|
@ -91,7 +89,6 @@ func (s *StubDNS) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *StubDNS) Present(ctx context.Context, challenge acme.Challenge) error {
|
func (s *StubDNS) Present(ctx context.Context, challenge acme.Challenge) error {
|
||||||
// get challenge parameters
|
// get challenge parameters
|
||||||
fqdn := dns.Fqdn(challenge.DNS01TXTRecordName())
|
fqdn := dns.Fqdn(challenge.DNS01TXTRecordName())
|
||||||
|
|
@ -120,7 +117,7 @@ func (s *StubDNS) Present(ctx context.Context, challenge acme.Challenge) error {
|
||||||
handler := s.make_handler(fqdn, content)
|
handler := s.make_handler(fqdn, content)
|
||||||
// could also use fqdn as pattern, but "." allows logging invalid requests
|
// could also use fqdn as pattern, but "." allows logging invalid requests
|
||||||
dns.HandleFunc(".", handler)
|
dns.HandleFunc(".", handler)
|
||||||
server := &dns.Server{Addr: s.Address, Net: "udp", TsigSecret: nil,}
|
server := &dns.Server{Addr: s.Address, Net: "udp", TsigSecret: nil}
|
||||||
go s.serve(server)
|
go s.serve(server)
|
||||||
|
|
||||||
// store the server for shutdown later
|
// store the server for shutdown later
|
||||||
|
|
@ -222,7 +219,6 @@ func (s *StubDNS) make_handler(fqdn string, txt string) dns.HandlerFunc {
|
||||||
return handler
|
return handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MarshalLogObject satisfies the zapcore.ObjectMarshaler interface.
|
// MarshalLogObject satisfies the zapcore.ObjectMarshaler interface.
|
||||||
func (m LoggableDNSMsg) MarshalLogObject(enc zapcore.ObjectEncoder) error {
|
func (m LoggableDNSMsg) MarshalLogObject(enc zapcore.ObjectEncoder) error {
|
||||||
// adapted version of MsgHdr.String() from github.com/miekg/dns
|
// adapted version of MsgHdr.String() from github.com/miekg/dns
|
||||||
|
|
@ -231,14 +227,30 @@ func (m LoggableDNSMsg) MarshalLogObject(enc zapcore.ObjectEncoder) error {
|
||||||
enc.AddString("status", dns.RcodeToString[m.Rcode])
|
enc.AddString("status", dns.RcodeToString[m.Rcode])
|
||||||
|
|
||||||
flag_array := func(arr zapcore.ArrayEncoder) error {
|
flag_array := func(arr zapcore.ArrayEncoder) error {
|
||||||
if m.Response {arr.AppendString("qr")}
|
if m.Response {
|
||||||
if m.Authoritative {arr.AppendString("aa")}
|
arr.AppendString("qr")
|
||||||
if m.Truncated {arr.AppendString("tc")}
|
}
|
||||||
if m.RecursionDesired {arr.AppendString("rd")}
|
if m.Authoritative {
|
||||||
if m.RecursionAvailable {arr.AppendString("ra")}
|
arr.AppendString("aa")
|
||||||
if m.Zero {arr.AppendString("z")}
|
}
|
||||||
if m.AuthenticatedData {arr.AppendString("ad")}
|
if m.Truncated {
|
||||||
if m.CheckingDisabled {arr.AppendString("cd")}
|
arr.AppendString("tc")
|
||||||
|
}
|
||||||
|
if m.RecursionDesired {
|
||||||
|
arr.AppendString("rd")
|
||||||
|
}
|
||||||
|
if m.RecursionAvailable {
|
||||||
|
arr.AppendString("ra")
|
||||||
|
}
|
||||||
|
if m.Zero {
|
||||||
|
arr.AppendString("z")
|
||||||
|
}
|
||||||
|
if m.AuthenticatedData {
|
||||||
|
arr.AppendString("ad")
|
||||||
|
}
|
||||||
|
if m.CheckingDisabled {
|
||||||
|
arr.AppendString("cd")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -305,7 +317,6 @@ func log_questions(enc zapcore.ObjectEncoder, questions *[]dns.Question) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Interface guards
|
// Interface guards
|
||||||
var (
|
var (
|
||||||
_ acmez.Solver = (*StubDNS)(nil)
|
_ acmez.Solver = (*StubDNS)(nil)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue