Repository navigation
fix: keep config defaults for keys a config file omits - #120
Merged
Merged
Conversation
The loader decoded the TOML file into a zero Config and passed each section to the With* options, which copy booleans and some ints as given. So any config file, even one without a [session] section, turned session.http_only off, set max_sessions_per_user to 0 (no limit) and turned security.cors.allow_credentials off. Running with no file kept the defaults. Decode the file on top of DefaultConfig, the defaults NewConfig now starts from, so an omitted key keeps its default and an explicit one still wins.
Member
|
Thanks for the PR, will look into it soon. |
Contributor
Author
|
no worries, thanks bro |
Member
|
I pushed a few updates to this PR. I hope you don't mind. Thanks again. |
Contributor
Author
|
np bro, |
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.
The config loader decodes the TOML file into a zero
Configand hands each section to theWith*options.WithSessionandWithSecuritycopy some fields as given, so any config file, even one with no[session]section, ends up with:session.http_only = false(defaulttrue), so the session cookie is readable from JavaScriptsession.max_sessions_per_user = 0(default5), which disables the limitsecurity.cors.allow_credentials = false(defaulttrue)Running with no config file keeps the defaults. That's why it doesn't show up in a quick local run.
The fix decodes the file on top of
DefaultConfig(), the defaultsNewConfignow starts from. A key the file omits keeps its default, and one it sets explicitly still wins. The new table-driven test incmd/shared/configloadercovers both. With the old loader, the two omitted-key cases fail.Library users who call
WithSessionwith a partialSessionConfigstill get the zero values for those fields. Fixing that needs pointer fields or similar, which is an API decision I've left to you.make format,go vet ./...,golangci-lint run(0 issues),make buildandgo test -race ./...(64 packages) all pass locally.AI disclosure: written with Claude Code (Claude Opus 5.5). I reviewed the diff before opening this.