api

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ErrorResponse{Code: 404, Status: "Resource not found."}

Functions

func Bind

func Bind(r *http.Request, dest interface{}) error

func Handler

func Handler(h HandlerFunc) http.HandlerFunc

func Render

func Render(w http.ResponseWriter, r *http.Request, response any) error

Render negotiates the content type and renders the response, defaulting to JSON. Response must implement fmt.Stringer to be rendered as plain text.

Types

type Binder

type Binder interface {
	Bind(value string) error
}

type ErrorResponse

type ErrorResponse struct {
	Err  error `json:"-"` // low-level runtime error
	Code int   `json:"-"` // http response status code

	Status  string `json:"status"`          // user-level status message
	Message string `json:"error,omitempty"` // application-level error message, for debugging
}

func Error

func Error(err error) *ErrorResponse

func InvalidRequestError

func InvalidRequestError(err error) *ErrorResponse

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

func (*ErrorResponse) Render

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

type Hex

type Hex []byte

func (*Hex) Bind

func (h *Hex) Bind(value string) error

func (Hex) MarshalJSON

func (h Hex) MarshalJSON() ([]byte, error)

func (*Hex) UnmarshalJSON

func (h *Hex) UnmarshalJSON(data []byte) error

type HexSlice

type HexSlice []Hex

func (*HexSlice) Bind

func (hs *HexSlice) Bind(value string) error

type Uint64Slice

type Uint64Slice []uint64

func (*Uint64Slice) Bind

func (us *Uint64Slice) Bind(value string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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