Skip to content

feat: add support for "auto" TTL#3

Merged
tomfrenzel merged 1 commit intolibdns:mainfrom
harrisonhjones:main
Apr 16, 2026
Merged

feat: add support for "auto" TTL#3
tomfrenzel merged 1 commit intolibdns:mainfrom
harrisonhjones:main

Conversation

@harrisonhjones
Copy link
Copy Markdown
Contributor

Thanks for this great library.

Why & Why

While playing around with it today I noticed I could not create records with an auto ttl. I was getting:

{"statusCode":400,"statusName":"BAD_REQUEST","code":"api.request.error","message":"ttlSeconds must not be null","timestamp":"2026-04-16T13:39:29.962990173Z","requestPath":"/integration/v1/sites/REDACTED/dns/policies","requestId":"6b2afeaa-6cf0-482c-a6d9-3de6fc04abe4"}

When I tried:

	newRecords, err := provider.AppendRecords(context.Background(), "REDACTED", []libdns.Record{
		libdns.Address{
			Name: "test",
			IP:   netip.MustParseAddr("REDACTED"),
			TTL:  0, // 0 = 'auto'
		},
	})

This change removes the omitempty from the JSON struct tag so that 0s are still marshalled to JSON correctly.

Testing

I made this change locally and then tried the above code snippet. It created the new record successfully. I checked the unifi console and I saw the new record with an auto TTL.

A TTLSeconds of `0` is valid within Unifi and represents "auto".
@tomfrenzel tomfrenzel changed the title Update unifi.go - Support "auto" TTL feat: add support for "auto" TTL Apr 16, 2026
@tomfrenzel
Copy link
Copy Markdown
Collaborator

Thanks for the contribution! LGTM 👍🏽

@tomfrenzel tomfrenzel merged commit 1fe4578 into libdns:main Apr 16, 2026
1 check passed
@tomfrenzel
Copy link
Copy Markdown
Collaborator

@harrisonhjones I did not notice at first but your change broke the creation of some record types (the ones that do not support TTL). I fixed it by setting the TTL to omitempty again but when no value was set, default it to 0. That way the record types that need it always have a number

@harrisonhjones
Copy link
Copy Markdown
Contributor Author

Neat. I figured that my change might have side effects; thanks for catching those so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants