Documentation ¶
Index ¶
- Variables
- func FormFile(r *http.Request, name string) (*multipart.FileHeader, error)
- func GetBeareToken(r *http.Request, name string) (string, error)
- func GetToken(r *http.Request, name string) (string, error)
- func GetValue(r *http.Request, key interface{}) interface{}
- func HealthCheck(w http.ResponseWriter, r *http.Request)
- func OKJSON(w http.ResponseWriter, data interface{})
- func OKText(w http.ResponseWriter, text string)
- func ReadCSVQuery(r *http.Request, key string, defaultValue []string) []string
- func ReadInt64Param(r *http.Request, name string) (int64, error)
- func ReadInt64Query(r *http.Request, key string, defaultValue int64) int64
- func ReadJSON(w http.ResponseWriter, r *http.Request, dst interface{}) error
- func ReadParams(r *http.Request, name string) string
- func ReadQuery(r *http.Request, key string, defaultValue string) string
- func SaveUploadedFile(file *multipart.FileHeader, dst string) error
- func SetValue(r *http.Request, key, value interface{}) *http.Request
- func WriteJSON(w http.ResponseWriter, status int, data interface{}, headers http.Header)
- func WriteStr(w http.ResponseWriter, status int, msg string, headers http.Header)
- type Config
- type Envelope
- type HandleHelper
- func (h *HandleHelper) AuthenticationRequire()
- func (h *HandleHelper) BadRequestErr(err error)
- func (h *HandleHelper) BadRequestMsg(msg string)
- func (h *HandleHelper) EditConflict()
- func (h *HandleHelper) FailedValidation(errs map[string]string)
- func (h *HandleHelper) InactiveAccount()
- func (h *HandleHelper) InvalidAuthenticationToken()
- func (h *HandleHelper) InvalidCredentials()
- func (h *HandleHelper) MethodNotAllow()
- func (h *HandleHelper) NotFound()
- func (h *HandleHelper) NotPermitted()
- func (h *HandleHelper) RateLimitExceede()
- func (h *HandleHelper) ServerErr(err error)
- type Middleware
- type RouterGroup
- func (g *RouterGroup) Delete(path string, handler http.HandlerFunc)
- func (g *RouterGroup) Get(path string, handler http.HandlerFunc)
- func (g *RouterGroup) Group(path string, mds ...Middleware) *RouterGroup
- func (g *RouterGroup) NewHandler(method, path string, handler http.HandlerFunc)
- func (g *RouterGroup) Patch(path string, handler http.HandlerFunc)
- func (g *RouterGroup) Post(path string, handler http.HandlerFunc)
- func (g *RouterGroup) Put(path string, handler http.HandlerFunc)
- func (g *RouterGroup) Routes(middlewares ...Middleware) http.Handler
- func (g *RouterGroup) Static(prefix string, dst string)
Constants ¶
This section is empty.
Variables ¶
var ErrNoToken = errors.New("no token")
ErrNoToken is returned when a token is not found in the request
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(http.StatusMethodNotAllowed, msg) }
MethodNotAllowed is a handler for method not found
Functions ¶
func GetBeareToken ¶ added in v0.0.14
GetBearerToken returns the bearer token from the request
func HealthCheck ¶ added in v0.0.13
func HealthCheck(w http.ResponseWriter, r *http.Request)
HealthCheckHandler is a handler for health check
func OKJSON ¶ added in v0.0.7
func OKJSON(w http.ResponseWriter, data interface{})
OKJSON handle 200 respose
func OKText ¶ added in v0.0.15
func OKText(w http.ResponseWriter, text string)
OKText handle 200 respose
func ReadCSVQuery ¶ added in v0.0.14
ReadCSVQuery returns the csv list query value with a defaut list from the request
func ReadInt64Param ¶ added in v0.0.14
ReadInt64Param returns the int64 param value in the request path
func ReadInt64Query ¶ added in v0.0.14
ReadInt64Query returns the int64 query value with a defaut value from the request
func ReadJSON ¶
func ReadJSON(w http.ResponseWriter, r *http.Request, dst interface{}) error
ReadJSON reads the request body and unmarshal it to the given struct, max size is 8MB
func ReadParams ¶ added in v0.0.7
ReadParam returns the string param value in the request path
func ReadQuery ¶ added in v0.0.14
ReadQuery returns the string query value with a defaut value from the request
func SaveUploadedFile ¶ added in v0.0.17
func SaveUploadedFile(file *multipart.FileHeader, dst string) error
SaveUploadedFile uploads the form file to specific dst.
Types ¶
type Config ¶
type Config struct { Limiter struct { Rps float64 Burst int Enabled bool } CORS struct { TrustedOrigins []string } Metrics bool }
Config is the configuration for the router
type Envelope ¶ added in v0.0.2
type Envelope map[string]interface{}
Envelope is a JSON envelope for better client response
type HandleHelper ¶ added in v0.1.0
type HandleHelper struct {
// contains filtered or unexported fields
}
HandleHelper is a handler for all requests
func NewHandleHelper ¶ added in v0.1.0
func NewHandleHelper(w http.ResponseWriter, r *http.Request) *HandleHelper
NewHandleHelper returns a new handler
func (*HandleHelper) AuthenticationRequire ¶ added in v0.1.0
func (h *HandleHelper) AuthenticationRequire()
AuthenticationRequire handle 401 response
func (*HandleHelper) BadRequestErr ¶ added in v0.1.0
func (h *HandleHelper) BadRequestErr(err error)
BadRequestErr handle 400 response with a error
func (*HandleHelper) BadRequestMsg ¶ added in v0.1.0
func (h *HandleHelper) BadRequestMsg(msg string)
HandleBadRequest handle 400 response with custom message
func (*HandleHelper) EditConflict ¶ added in v0.1.0
func (h *HandleHelper) EditConflict()
EditConflict handle 409 response
func (*HandleHelper) FailedValidation ¶ added in v0.1.0
func (h *HandleHelper) FailedValidation(errs map[string]string)
FailedValidation handle 400 response
func (*HandleHelper) InactiveAccount ¶ added in v0.1.0
func (h *HandleHelper) InactiveAccount()
InactiveAccount handle 403 response
func (*HandleHelper) InvalidAuthenticationToken ¶ added in v0.1.0
func (h *HandleHelper) InvalidAuthenticationToken()
InvalidAuthenticationToken handle 401 response
func (*HandleHelper) InvalidCredentials ¶ added in v0.1.0
func (h *HandleHelper) InvalidCredentials()
InvalidCredentials handle 400 response
func (*HandleHelper) MethodNotAllow ¶ added in v0.1.0
func (h *HandleHelper) MethodNotAllow()
MethodNotAllow handle 405 response
func (*HandleHelper) NotFound ¶ added in v0.1.0
func (h *HandleHelper) NotFound()
NotFound handle 404 response
func (*HandleHelper) NotPermitted ¶ added in v0.1.0
func (h *HandleHelper) NotPermitted()
NotPermitted handle 403 response
func (*HandleHelper) RateLimitExceede ¶ added in v0.1.0
func (h *HandleHelper) RateLimitExceede()
RateLimitExceede handle 429 response
func (*HandleHelper) ServerErr ¶ added in v0.1.0
func (h *HandleHelper) ServerErr(err error)
ServerErr handle 500 response
type Middleware ¶ added in v0.0.11
type Middleware func(http.HandlerFunc) http.HandlerFunc
Middleware is a function that takes a http.HandlerFunc and returns a http.HandlerFunc.
type RouterGroup ¶ added in v0.0.9
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup is a group of routes
func DefaultRouterGroup ¶ added in v0.0.12
func DefaultRouterGroup() *RouterGroup
DefaultRouterGroup return a new routergroup with default router config
func NewRouterGroup ¶ added in v0.0.12
func NewRouterGroup(conf *Config) (*RouterGroup, error)
NewRouterGroup return a new routergroup
func (*RouterGroup) Delete ¶ added in v0.0.9
func (g *RouterGroup) Delete(path string, handler http.HandlerFunc)
Delete is a shortcut for NewHandler(http.MethodDelete, path, handler)
func (*RouterGroup) Get ¶ added in v0.0.9
func (g *RouterGroup) Get(path string, handler http.HandlerFunc)
Get is a shortcut for NewHandler(http.MethodGet, path, handler)
func (*RouterGroup) Group ¶ added in v0.0.9
func (g *RouterGroup) Group(path string, mds ...Middleware) *RouterGroup
Group add a prefix to all path, for each Gropu call prefix will accumulate while middleware don't
func (*RouterGroup) NewHandler ¶ added in v0.0.13
func (g *RouterGroup) NewHandler(method, path string, handler http.HandlerFunc)
NewHandler handle new http request
func (*RouterGroup) Patch ¶ added in v0.0.9
func (g *RouterGroup) Patch(path string, handler http.HandlerFunc)
Patch is a shortcut for NewHandler(http.MethodPatch, path, handler)
func (*RouterGroup) Post ¶ added in v0.0.9
func (g *RouterGroup) Post(path string, handler http.HandlerFunc)
Post is a shortcut for NewHandler(http.MethodPost, path, handler)
func (*RouterGroup) Put ¶ added in v0.0.9
func (g *RouterGroup) Put(path string, handler http.HandlerFunc)
Put is a shortcut for NewHandler(http.MethodPut, path, handler)
func (*RouterGroup) Routes ¶ added in v0.0.10
func (g *RouterGroup) Routes(middlewares ...Middleware) http.Handler
Routes return http.Handler for http server must be call after add all custum path handler
func (*RouterGroup) Static ¶ added in v0.0.17
func (g *RouterGroup) Static(prefix string, dst string)
Static is a shortcut for NewHandler(http.MethodDelete, path, handler)