docs: fix SessionConfig struct literal syntax in handler examples#577
Draft
github-actions[bot] wants to merge 1 commit into
Draft
docs: fix SessionConfig struct literal syntax in handler examples#577github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Handler types (AuthHandler, MagicLinkHandler, PasskeyHandler, OAuth2Handler) embed SessionConfig rather than declaring its fields directly. Go does not allow promoted fields as keys in composite struct literals; the embedded type name must be used instead. Update all affected code examples across: - docs/handler/auth.md - docs/handler/magic-links.md - docs/handler/passkeys.md - docs/handler/oauth2.md - docs/index.md - docs/tutorial.md Also fix docs/tutorial.md: maintenance.StartCleanup now takes a *slog.Logger as its second argument; pass nil to use slog.Default(). The previous example omitted this parameter entirely, making the code non-compilable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Several documentation code examples used invalid Go syntax: they initialized promoted fields from the embedded
SessionConfigstruct directly in handler struct literals, which the Go compiler rejects. The Go specification requires that struct literal keys be field names declared at the top level of the struct type — promoted fields from an embedded type must be initialized via the embedded type name.Example of broken syntax (from docs):
Corrected syntax (consistent with README):
Files changed
docs/handler/auth.mdAuthHandlerstruct literal used promotedSessionConfigfieldsdocs/handler/magic-links.mdMagicLinkHandlerstruct literal used promotedSessionConfigfieldsdocs/handler/passkeys.mdPasskeyHandlerstruct literal used promotedSessionConfigfieldsdocs/handler/oauth2.mdOAuth2Handlerstruct literal used promotedSessionConfigfieldsdocs/index.mdAuthHandlerexample used promotedSessionConfigfieldsdocs/tutorial.mdAuthHandlerexample +maintenance.StartCleanupmissingnillogger argumentThe
docs/tutorial.mdfix also corrects a second issue:maintenance.StartCleanuptakes(ctx, logger, interval, cleaners...)but the tutorial called(ctx, interval, cleaners...), omitting the required*slog.Loggerparameter. The corrected call passesnil(which usesslog.Default()at each log site).All fixes match the correct syntax already present in
README.md.Add this agentic workflows to your repo
To install this agentic workflow, run