jsonhttp

package
v0.4.12 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package jsonhttp provides shared HTTP helpers for AWS JSON-protocol services. It handles the application/x-amz-json-1.1 content type and error envelope that Lambda, SSM, Secrets Manager, and similar services use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode[T any](w http.ResponseWriter, r *http.Request) (T, bool)

Decode decodes the JSON request body into T. If T implements Contract, Validate() is called automatically. Returns (value, true) on success, writes an error response and returns (zero, false) on failure.

func Error

func Error(w http.ResponseWriter, status int, code, message string)

Error writes an AWS-shaped JSON error response.

func Write

func Write(w http.ResponseWriter, status int, v any)

Write encodes v as JSON with the AWS JSON content type.

Types

type Contract

type Contract interface {
	Validate() error
}

Contract is implemented by request structs that know how to validate themselves. Decode automatically calls Validate() if the decoded type satisfies this interface.

Jump to

Keyboard shortcuts

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