Helpers
The JSON and FromJSON body helpers and the Logger interface.
Two small helpers cover the common JSON round-trip, and the Logger interface is the surface the client writes diagnostics to.
JSON
func JSON(data any) (string, error)Marshals a value to a JSON string, for building a request Body. It returns the marshal error wrapped.
body, err := http.JSON(map[string]string{"name": "ada"})FromJSON
func FromJSON(data []byte) (T, error)Unmarshals a response body into a value of the type parameter. Decode only after checking the status code, since an error body is still valid JSON.
user, err := http.FromJSON[User](resp.Body)Logger
type Logger interface {
Trace(msg string, args ...any)
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
Error(msg string, args ...any)
}The minimal leveled logging surface the client writes to, injected with WithLogger. It is satisfied structurally by github.com/toaweme/log, so that logger passes directly with no adapter. There is deliberately no With or handler method, so an external logger fits without wrapping, and per-request context is passed as args on each call. See Configuring the client.