httpjson

package
v0.0.0-...-dc10c7c Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidContentType = errors.New("Content-Type must be application/json")
)

Functions

func Decode

func Decode[T any](r *http.Request) (T, error)

func Encode

func Encode[T any](w http.ResponseWriter, status int, v T)

func EncodeError

func EncodeError(w http.ResponseWriter, err error)

Types

type Error

type Error struct {
	Status  int           `json:"-"`
	Code    string        `json:"code,omitempty"`
	Message string        `json:"message"`
	Details []ErrorDetail `json:"details,omitempty"`
}

func (Error) Error

func (e Error) Error() string

type ErrorDetail

type ErrorDetail struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message"`
	Field   string `json:"field,omitempty"`
}

Jump to

Keyboard shortcuts

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