refactor(web): extract magic cache and cookie TTL constants#1304
Merged
adamshiervani merged 1 commit intojetkvm:devfrom Mar 17, 2026
Merged
refactor(web): extract magic cache and cookie TTL constants#1304adamshiervani merged 1 commit intojetkvm:devfrom
adamshiervani merged 1 commit intojetkvm:devfrom
Conversation
web.go had three hardcoded duration values scattered across seven call sites: - 31536000 (1 year) for immutable asset and robots.txt Cache-Control headers, appearing on lines 123 and 140 - 300 (5 minutes) for cacheable static file headers, line 131 - 7*24*60*60 (1 week) for authToken cookie MaxAge, appearing on lines 535, 706, 760, and 893 Extract these into named constants (cacheImmutableMaxAge, cacheShortMaxAge, authTokenMaxAge) at the top of the file. No behavioural change. The constants make the intent readable at each call site and give maintainers a single place to adjust these values. Signed-off-by: Alex Howells <alex@howells.me>
adamshiervani
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
web.gohas three hardcoded duration values scattered acrossseven call sites:
31536000(1 year),300(5 minutes), and7*24*60*60(1 week). The numeric literals obscure intent andmake it easy to introduce inconsistencies if one site is changed
but not the others.
Fix
Extract into named constants at the top of
web.go:cacheImmutableMaxAge(365 days) — used for/static/assets/immutable/and/robots.txtcacheShortMaxAge(5 minutes) — used for other cacheable static filesauthTokenMaxAge(1 week) — used across the fourSetCookiecall sites for login, password create, password update, and setupNo behavioural change. The
Cache-Controlheaders are now builtwith
fmt.Sprintfreferencing the constants instead of inliningthe raw numbers.