Skip to content

feat: add generic payload decoding helpers - #13

Merged
cmilesio merged 1 commit into
mainfrom
feat/go-1.27-generic-methods
Aug 23, 2026
Merged

feat: add generic payload decoding helpers#13
cmilesio merged 1 commit into
mainfrom
feat/go-1.27-generic-methods

Conversation

@cmilesio

@cmilesio cmilesio commented Aug 23, 2026

Copy link
Copy Markdown
Member

What

Add Job.PayloadAs[T] and Message.PayloadAs[T] for typed JSON payload decoding. Existing Bind methods remain unchanged, with tests covering behavior and error parity plus generated examples for both payload owners.

Raise all 12 Queue modules, workspace metadata, documentation, release inventory, and minimum-version CI coverage to Go 1.27. The sibling-module replace directives used by repository-wide tests remain in place.

Before and after

Both concrete payload owners can now return the decoded type instead of asking callers to prepare mutable state.

Message.PayloadAs

Before:

var payload SendEmail
err := message.Bind(&payload)

After:

payload, err := message.PayloadAs[SendEmail]()

Job.PayloadAs

Before:

var payload SendEmail
err := job.Bind(&payload)

After:

payload, err := job.PayloadAs[SendEmail]()

Existing Bind methods remain the right choice when a caller intentionally wants to populate an existing value.

Why

Queue's pointer-based decoding was another visible scar from the old generic-method limitation. Go 1.27 lets payload ownership read naturally: ask the job or message for the type you need, receive it directly, and handle the same errors as before.

Performance

The result-returning methods add no allocation cost. Job Bind and PayloadAs both use 24 B and 2 allocations; Message Bind and PayloadAs both use 8 B and 1 allocation. Repeated single-core runs keep both call forms in the same timing range.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cmilesio
cmilesio merged commit 77aab59 into main Aug 23, 2026
25 checks passed
@cmilesio cmilesio changed the title Add generic payload decoding helpers feat: add generic payload decoding helpers Aug 23, 2026
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