Skip to content

fix(readme): make the README code samples compile - #577

Merged
manovotny merged 2 commits into
v2from
michael/readme-code-samples-compile
Jul 7, 2026
Merged

fix(readme): make the README code samples compile#577
manovotny merged 2 commits into
v2from
michael/readme-code-samples-compile

Conversation

@manovotny

@manovotny manovotny commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to https://github.com/clerk/clerk/pull/2891, which fixed the same issues on the Go quickstart docs page and flagged this README as having the same config.Key = "sk_live_XXX" bug. clerk.ClientConfig embeds BackendConfig, whose Key field is a *string, so the snippet didn't compile. Auditing the rest of the README's Go snippets turned up several more compile errors, fixed here as well.

Changes

  • Usage with a client: config.Key = "sk_live_XXX"config.Key = clerk.String("sk_live_XXX") (Key is a *string).
  • Both $resource$ usage templates: repeated resource, err := ... redeclarations → = for Get/Update; Delete now uses deletedResource, err := since Delete returns *clerk.DeletedResource, not the resource type.
  • Concrete organization/user example: added missing context and fmt imports; organizationmembership.List(ctx, params) passed an undefined variable → &listParams; ListParams.OrganizationID is required (it builds the /organizations/{id}/memberships path) and is now set to org.ID; memberships.TotalCount < 0 can never be true → == 0; memberships[0] indexed a struct → memberships.OrganizationMemberships[0]; membership.UserID doesn't exist → membership.PublicUserData.UserID; added error handling and a final fmt.Println(usr.ID) so err and usr are no longer declared-and-not-used.
  • Accessing API responses / Errors: bare expression statements (dmn.Response.TraceID, apiErr.TraceID, apiErr.Response.RawJSON) are "evaluated but not used" compile errors → printed with fmt.Println.
  • Testing snippets: func (r *mockRoundTripper) RoundTrip(r *http.Request) reused r for receiver and parameter (duplicate argument) → receiver renamed to m; stub bodies were missing return statements → minimal returns added; the last custom backend took reader *clerk.ResponseReader (pointer to interface, doesn't satisfy clerk.Backend) → clerk.ResponseReader; the two client-based tests declared client without using it → a client.Get call added.

The two $resource$ usage blocks stay illustrative fragments by design — beyond the $resource$ placeholder they hold top-level statements (ctx := ..., clerk.SetKey(...)) that aren't valid at Go file scope, so they don't compile standalone even with a real resource substituted. They teach the CRUD shape; the reader drops them into a function and uses the results (the // do something with the resource comment marks that). The complete, compile-clean runnable example immediately follows them. This PR removes their genuine compile bugs (the := redeclarations and the wrong Delete return binding) without turning the concise shape illustrations into full programs.

Verification

All 13 go fences were extracted from the edited README into a scaffold module (each snippet in its own package, fragments wrapped with the minimal package/func boilerplate a reader would supply, $resource$ substituted with user) requiring github.com/clerk/clerk-sdk-go/v2 at this branch's HEAD. go build ./... and go vet ./... both pass. As a negative control, the same harness against the unedited README produces 20 compile-error lines.

References

🤖 Generated with Claude Code

The "Usage with a client" snippet assigned a string literal to
clerk.ClientConfig.Key, which is a *string. Fixing that surfaced more
compile errors across the README's Go snippets, so every snippet was
audited and verified by extracting them into a scaffold module and
running go build and go vet against the SDK at HEAD.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@manovotny
manovotny requested a review from a team as a code owner July 7, 2026 20:32
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@manovotny
manovotny merged commit 0a8235e into v2 Jul 7, 2026
7 checks passed
@manovotny
manovotny deleted the michael/readme-code-samples-compile branch July 7, 2026 20:47
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