Skip to content

Commit ca52dcb

Browse files
committed
Fix for Caddy's documentation generator
Caddy's documentation generator doesn't work with generics, nor with custom JSON representations.
1 parent c763026 commit ca52dcb

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

dns_config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/caddyserver/caddy/v2"
88
"github.com/caddyserver/certmagic"
9-
"github.com/liujed/goutil/optionals"
109
)
1110

1211
type DNSConfig struct {
@@ -15,7 +14,11 @@ type DNSConfig struct {
1514
Provider certmagic.DNSProvider `json:"-"`
1615

1716
// The TTL to use for the DNS TXT records when answering challenges.
18-
TTL optionals.Optional[caddy.Duration] `json:"ttl"`
17+
//
18+
// XXX This should be an Optional[caddy.Duration], but Caddy's documentation
19+
// generator can handle neither generics nor types with custom JSON
20+
// representations.
21+
TTL *caddy.Duration `json:"ttl,omitempty"`
1922

2023
// Custom DNS resolvers to prefer over system/built-in defaults. Often
2124
// necessary to configure when using split-horizon DNS.

handler.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ func (h *Handler) handleDNSRequest(
209209
}
210210

211211
// Build the DNS record to create/delete.
212-
ttl := time.Duration(h.DNS.TTL.GetOrDefault(0))
213-
if mode == hmCleanup {
214-
ttl = 0
212+
ttl := time.Duration(0)
213+
if mode != hmCleanup && h.DNS.TTL != nil {
214+
ttl = time.Duration(*h.DNS.TTL)
215215
}
216216
records := []libdns.Record{
217217
libdns.TXT{
@@ -297,7 +297,8 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
297297
if err != nil {
298298
return err
299299
}
300-
h.DNS.TTL = optionals.Some(caddy.Duration(parsedTTL))
300+
caddyTTL := caddy.Duration(parsedTTL)
301+
h.DNS.TTL = &caddyTTL
301302

302303
case "resolvers":
303304
h.DNS.Resolvers = d.RemainingArgs()

0 commit comments

Comments
 (0)