handler

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 16 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AbortMiddleware = Middleware(func(next http.HandlerFunc) http.HandlerFunc {
	return VoidHandlerFunc
})

AbortMiddleware ...

View Source
var ErrNoToken = errors.New("no token")

ErrNoToken is returned when a token is not found in the request

View Source
var MethodNotAllowed http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
	msg := fmt.Sprintf("the %s mehtod is not supported for this resource", r.Method)
	errResponse(w, http.StatusMethodNotAllowed, msg)
}

MethodNotAllowed method not found handler

View Source
var VoidHandlerFunc = http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
})

VoidHandlerFunc ...

View Source
var VoidMiddleware = Middleware(func(next http.HandlerFunc) http.HandlerFunc {
	return next
})

VoidMiddleware ...

Functions

func AuthenticationRequire added in v0.3.3

func AuthenticationRequire(w http.ResponseWriter)

AuthenticationRequire 401 response tip

func BadRequestErr added in v0.3.3

func BadRequestErr(w http.ResponseWriter, err error)

BadRequestErr 400 response with a error

func BadRequestMsg added in v0.3.3

func BadRequestMsg(w http.ResponseWriter, msg string)

HandleBadRequest 400 response with custom message

func ClearSimpleCookie added in v0.5.5

func ClearSimpleCookie(w http.ResponseWriter, name string)

ClearSimpleCookie clear a named simple cookie

func EditConflict added in v0.3.3

func EditConflict(w http.ResponseWriter)

EditConflict 409 response

func FailedValidation added in v0.3.3

func FailedValidation(w http.ResponseWriter, errs map[string]string)

FailedValidation 400 response

func GetBeareToken

func GetBeareToken(r *http.Request, name string) (string, error)

GetBearerToken returns the bearer token from the request

func GetToken

func GetToken(r *http.Request, name string) (string, error)

GetToken returns the token from the request query > header > cookie

func GetValue

func GetValue(r *http.Request, key any) any

GetValue gets a value from the request context.

func GzipMiddleware added in v0.3.2

func GzipMiddleware(next http.HandlerFunc) http.HandlerFunc

GipMiddleware good for serving static html/js/css file

func HealthCheck

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

HealthCheckHandler a simple health check

func InactiveAccount added in v0.3.3

func InactiveAccount(w http.ResponseWriter)

InactiveAccount 403 response for inactionaccount

func InvalidAuthenticationToken added in v0.3.3

func InvalidAuthenticationToken(w http.ResponseWriter)

InvalidAuthenticationToken 401 response

func InvalidCredentials added in v0.3.3

func InvalidCredentials(w http.ResponseWriter)

InvalidCredentials 400 response for bad reruest

func MethodNotAllow added in v0.3.3

func MethodNotAllow(w http.ResponseWriter)

MethodNotAllow 405 response

func MetricsMiddleware added in v0.1.0

func MetricsMiddleware(next http.HandlerFunc) http.HandlerFunc

MetricsMiddleware middleware enable expvar profile

func NotFound added in v0.3.3

func NotFound(w http.ResponseWriter)

NotFound general 404 response

func NotFoundMsg added in v0.0.14

func NotFoundMsg(msg string) http.HandlerFunc

NotFoundMsg method not found with custom message

func NotPermitted added in v0.3.3

func NotPermitted(w http.ResponseWriter)

NotPermitted 403 response

func OKJSON

func OKJSON(w http.ResponseWriter, data any)

OKJSON response 200 respose with a json data

func OKText

func OKText(w http.ResponseWriter, text string)

OKText response 200 with the plain text

func OkHandler added in v0.4.27

func OkHandler(data any) http.HandlerFunc

Ok is a high order func

func RateLimitExceede added in v0.3.3

func RateLimitExceede(w http.ResponseWriter)

RateLimitExceede 429 response

func ReadCSVQuery

func ReadCSVQuery(r *http.Request, key string, defaultValue []string) []string

ReadCSVQuery returns the csv list query value with a defaut list from the request

func ReadInt64PathParam added in v0.3.9

func ReadInt64PathParam(r *http.Request, name string) (int64, error)

ReadInt64PathParam returns the int64 param value in the request path

func ReadInt64Query

func ReadInt64Query(r *http.Request, key string, defaultValue int64) int64

ReadInt64Query returns the int64 query value with a defaut value from the request

func ReadIntPathParam added in v0.5.3

func ReadIntPathParam(r *http.Request, name string) (int, error)

ReadIntPathParam returns a int param value in the request path

func ReadIntQuery added in v0.5.3

func ReadIntQuery(r *http.Request, key string, defaultValue int) int

ReadIntQuery returns a int query value with a defaut value from the request

func ReadJSON

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

ReadJSON reads the request body and unmarshal it to the given struct

func ReadMaxJSON added in v0.3.4

func ReadMaxJSON(w http.ResponseWriter, r *http.Request, dst any, max int64) error

ReadJSON reads the request body up to the max size and unmarshal it to the given struct

func ReadPathParam added in v0.3.9

func ReadPathParam(r *http.Request, name string) string

ReadPathParam returns the string param value in the request path

func ReadQuery

func ReadQuery(r *http.Request, key string, defaultValue string) string

ReadQuery returns the string query value with a defaut value from the request

func RecoverPanicMiddleware added in v0.1.0

func RecoverPanicMiddleware(next http.HandlerFunc) http.HandlerFunc

RecoverPanicMiddleware middleware

func SaveFormFile added in v0.3.4

func SaveFormFile(r *http.Request, name, dir string) (string, error)

SaveFormFile write file to a dir with upload filename.

func ServerErr added in v0.3.3

func ServerErr(w http.ResponseWriter, err error)

ServerErr a general 500 response with an err

func ServerErrAny added in v0.4.4

func ServerErrAny(w http.ResponseWriter, msg any)

ServerErrAny a general 500 response

func SetSimpleCookie added in v0.4.21

func SetSimpleCookie(w http.ResponseWriter, r *http.Request, k, v string)

SetSimpleCookie set key value within a week

func SetValue

func SetValue(r *http.Request, key, value any) *http.Request

SetValue sets a value on the returned request.

func Version added in v0.4.27

func Version(ver string) http.HandlerFunc

Version response version

func WriteFormFile added in v0.3.5

func WriteFormFile(r *http.Request, name string, dst io.Writer) error

WriteFormFile write file to a io.Writer.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data any, headers http.Header)

writeJSON writes a JSON object to the response.

func WriteStr

func WriteStr(w http.ResponseWriter, status int, msg string, headers http.Header)

WriteStr writes a string to the response.

Types

type Envelope

type Envelope map[string]any

Envelope is a JSON envelope for better client response

type Middleware

type Middleware func(http.HandlerFunc) http.HandlerFunc

Middleware takes a http.HandlerFunc and returns a http.HandlerFunc.

func Aggregate added in v0.4.19

func Aggregate(mds ...Middleware) Middleware

Aggregate middlewares.

func Append added in v0.4.19

func Append(base, later Middleware) Middleware

Append middleware after base middleware.

func CORSMiddleware added in v0.1.0

func CORSMiddleware(trustedOrigins []string) Middleware

CORSMiddleware unblock trustedOrigins domains

func Insert added in v0.4.19

func Insert(base, first Middleware) Middleware

Insert middleware befer base middlware

func RateLimitMiddleware added in v0.1.0

func RateLimitMiddleware(rps float64, brust int) Middleware

RateLimitMiddleware return a middle

func TokenMiddleware added in v0.1.0

func TokenMiddleware(check func(string) (bool, error)) Middleware

TokenMiddleware GetToken then use check token

type PathRegs added in v0.3.9

type PathRegs string

PathRegs for ctx key

const (
	ParamsCtxKey   PathRegs = "path_param_names"
	ParamsCtxValue PathRegs = "path_param_values"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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