Skip to content

client: allow nil body in DoJSON#2

Merged
dankinder merged 3 commits into
mainfrom
dojson-allow-nil-body
Apr 24, 2026
Merged

client: allow nil body in DoJSON#2
dankinder merged 3 commits into
mainfrom
dojson-allow-nil-body

Conversation

@dankinder
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the kbhttp JSON client helpers to support requests where callers intentionally do not want to decode a response body (e.g., 204 No Content responses).

Changes:

  • Documented that DoJSON/GetJSON/PostJSON/PutJSON/DeleteJSON allow passing nil as the decode target to skip decoding.
  • Updated Client.DoJSON to return early when target == nil.
  • Added a test asserting DoJSON succeeds with a nil target on a 204 No Content response.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
client.go Adds documentation and implements early-return behavior when target is nil.
client_test.go Adds coverage for DoJSON(req, nil) when the server responds with HTTP 204.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread client.go
Comment thread client.go Outdated
Comment on lines 95 to 96
if err := json.NewDecoder(resp.Body).Decode(&target); err != nil {
return fmt.Errorf("got %d code and failed to decode response body: %w", resp.StatusCode, err)
dankinder and others added 2 commits April 24, 2026 17:08
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Since target is already an interface, no need for more indirection, it
could cause unexpected behavior.
@dankinder dankinder merged commit a2b2c66 into main Apr 24, 2026
1 check passed
@dankinder dankinder deleted the dojson-allow-nil-body branch April 24, 2026 21:10
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