httplib

package
v0.0.0-...-a61272a Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindJSON

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

Decodes a request body to v using encoding/json.

If v implements the Validator interface, calls Validate.

func DefaultErrorHandler

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

func F

func F(next HandlerFunc) http.Handler

Creates a new http.Handler from a httplib.HandlerFunc

func HF

func HF(next HandlerFunc) http.HandlerFunc

Creates a new http.HandlerFunc from a httplib.HandlerFunc

func JSON

func JSON(w http.ResponseWriter, status int, v any) error

Writes a JSON response using encoding/json.

func New

func New(next Handler) http.Handler

Creates a new http.Handler from a httplib.Handler

func NewWithHandler

func NewWithHandler(next Handler, eh ErrorHandler) http.Handler

Creates a new http handler with a custom error handler func

Types

type ErrorHandler

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

type ErrorResponse

type ErrorResponse struct {
	Message string         `json:"message"`
	Details map[string]any `json:"details"`
	Status  int            `json:"status"`
}

Default error response

type Handler

type Handler interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request) error
}

type HandlerFunc

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

func (HandlerFunc) ServeHTTP

func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error

type Validator

type Validator interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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