util

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MaxBytes = 1024 * 1024

Limit the size of the request body to 1MB.

Variables

This section is empty.

Functions

func BadRequestResponse

func BadRequestResponse(w http.ResponseWriter, r *http.Request, errors map[string]string)

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, r *http.Request, status int, message any)

func MethodNotAllowedResponse

func MethodNotAllowedResponse(w http.ResponseWriter, r *http.Request)

func NotFoundResponse

func NotFoundResponse(w http.ResponseWriter, r *http.Request)

func PageSizeToLimitOffset

func PageSizeToLimitOffset(page, size int) (int, int)

Convert user-friendly "page/size" pagination to DB-friendly "limit/offset".

func ReadBody

func ReadBody(w http.ResponseWriter, r *http.Request) io.Reader

func ReadInt

func ReadInt(qs url.Values, key string, defaultValue int, v *validator.Validator) int

func ReadJSON

func ReadJSON(r io.Reader, dst any, strict bool) error

Let's Go Further - Chapter 4.3

func ServerErrorResponse

func ServerErrorResponse(w http.ResponseWriter, r *http.Request, err error)

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, src any, header http.Header) error

Let's Go Further - Chapter 3.2

Types

This section is empty.

Jump to

Keyboard shortcuts

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