restapi

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeRequest

func DecodeRequest(r *http.Request, v any) error

DecodeRequest decodes the request body as JSON into the provided value.

func EncodeResponse

func EncodeResponse(w http.ResponseWriter, status int, data any) (int, error)

EncodeResponse sets the Content-Type header field to application/json, and writes to the response writer with the given status code and data encoded as JSON.

If data is nil, only the status code is written and no data is encoded.

If data is of type io.Reader or []byte, it is assumed to be encoded JSON and is written directly to the response writer.

Types

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request) (status int, err error)

HandlerFunc is like http.HandlerFunc, but returns a status code and an error.

Jump to

Keyboard shortcuts

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