Skip to content

chore: encapsulate Ctx.Patch behind a method#98

Merged
joaomdsg merged 1 commit into
mainfrom
chore/encapsulate-ctx-patch
Jun 9, 2026
Merged

chore: encapsulate Ctx.Patch behind a method#98
joaomdsg merged 1 commit into
mainfrom
chore/encapsulate-ctx-patch

Conversation

@joaomdsg

@joaomdsg joaomdsg commented Jun 9, 2026

Copy link
Copy Markdown
Member

Next API-surface cleanup (follows #97).

Finding

Ctx.Patch was the only exported field across every otherwise-opaque runtime type (Ctx, CtxR, Session, File, Ticker, App, Group) — all of which expose state via methods. A lone mutable public field let callers do ctx.Patch = nil / swap the handle, and broke the all-methods consistency of Ctx.

Change

  • Unexport the field Patchpatch.
  • Add func (ctx *Ctx) Patch() *Patch, mirroring Request() / Session() / Writer(). Still a plain field load (handle allocated eagerly in newCtx).
  • Call sites: ctx.Patch.Signal(...)ctx.Patch().Signal(...).

Breaking change, but pre-1.0 (v0.5.0) and a strict hardening — the runtime's push handle can no longer be reassigned out from under it.

Verification

go build, go vet, gofmt -l (clean), go test -race ./... — all green (incl. maplibre plugin tests that used the handle).

Ctx.Patch was the only exported field across every otherwise-opaque
runtime type (Ctx, CtxR, Session, File, Ticker, App, Group) — all of
which expose state through methods. A lone mutable public field let
callers reassign or nil the push handle (ctx.Patch = nil) and broke the
all-methods consistency of the type.

Unexport the field to `patch` and add `func (ctx *Ctx) Patch() *Patch`,
matching the shape of Request(), Session(), Writer(). The handle is
still allocated eagerly in newCtx, so the accessor is a plain field load.

Call sites move from `ctx.Patch.Signal(...)` to `ctx.Patch().Signal(...)`.
Breaking change, but pre-1.0 and a strict hardening — the field can no
longer be swapped out from under the runtime.
@joaomdsg
joaomdsg merged commit d144309 into main Jun 9, 2026
4 checks passed
@joaomdsg
joaomdsg deleted the chore/encapsulate-ctx-patch branch June 9, 2026 12:23
joaomdsg added a commit that referenced this pull request Jun 10, 2026
…e scope (#109)

- Document WithMaxUploadSize (32 MiB multipart) + WithRequestTooLarge
  hook across file-uploads, production, troubleshooting guides
- Fix stale ctx.Patch field form -> ctx.Patch() method (post #98)
- Note WithRequestTooLarge covers action POSTs only; SSE-close bodies
  always get the bare 413
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.

1 participant