jsonbody

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package jsonbody holds small stdlib helpers for JSON HTTP bodies: marshal a value into a request-body reader (with its content type) and unmarshal response bytes back into a value. It is byte-level wire framing only — it knows nothing about LLM messages, tools, usage, or provider semantics.

Index

Constants

View Source
const ContentType = "application/json"

ContentType is the media type a JSON body advertises. Exported so callers (codecs, custom encoders) set the request Content-Type from a single source of truth.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, v any) error

Decode unmarshals JSON bytes into v. v is `any` because this is the JSON serialization boundary.

func Encode

func Encode(v any) (io.Reader, string, error)

Encode marshals v to a JSON body, returning an io.Reader over the bytes and the application/json content type. v is `any` because this is the JSON serialization boundary, where the repo rule permits it.

Types

type DecodeError

type DecodeError struct {
	Err error
}

DecodeError wraps a JSON unmarshal failure. Typed per the repo rule.

func (*DecodeError) Error

func (e *DecodeError) Error() string

func (*DecodeError) Unwrap

func (e *DecodeError) Unwrap() error

type EncodeError

type EncodeError struct {
	Err error
}

EncodeError wraps a JSON marshal failure. Typed per the repo rule so callers can errors.As it rather than string-matching.

func (*EncodeError) Error

func (e *EncodeError) Error() string

func (*EncodeError) Unwrap

func (e *EncodeError) Unwrap() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL