json

package
v0.0.0-...-e705344 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package json provides utility functions for handling JSON encoding and decoding in HTTP requests and responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadJSON

func ReadJSON(w http.ResponseWriter, r *http.Request, dst any) error

ReadJSON reads and decodes JSON from the request body into the provided destination struct. It also performs various checks and returns detailed error messages for different types of JSON decoding errors.

func ReadUUIDPath

func ReadUUIDPath(r http.Request) (uuid.UUID, error)

ReadUUIDPath extracts and parses a UUID from the request path, returning an error if the UUID is invalid.

func RespondWithJSON

func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})

RespondWithJSON encodes the given payload to JSON and writes it to the response writer with the specified HTTP status code.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data models.Envelope, headers http.Header) error

WriteJSON encodes the given data to JSON with indentation and writes it to the response writer with the specified HTTP status code and headers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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