Documentation ¶
Overview ¶
Package ngamux is simple HTTP router for Go that compatible with net/http, the standard library to serve HTTP. Designed to make everything goes in simple way.
Index ¶
- Variables
- func WithErrorHandler(globalErrorHandler Handler) func(*Config)
- func WithLogLevel(level LogLevel) func(*Config)
- func WithTrailingSlash() func(*Config)
- type Config
- type Handler
- type KeyContext
- type LogLevel
- type Map
- type MiddlewareFunc
- type Ngamux
- func (mux *Ngamux) All(url string, handler Handler)
- func (mux Ngamux) Config() Config
- func (mux *Ngamux) Delete(url string, handler Handler)
- func (mux *Ngamux) Get(url string, handler Handler)
- func (mux *Ngamux) Group(url string, middlewares ...MiddlewareFunc) *Ngamux
- func (mux *Ngamux) Head(url string, handler Handler)
- func (m Ngamux) Log(level LogLevel, message string, data ...any)
- func (mux *Ngamux) Patch(url string, handler Handler)
- func (mux *Ngamux) Post(url string, handler Handler)
- func (mux *Ngamux) Put(url string, handler Handler)
- func (mux *Ngamux) ServeHTTP(rw http.ResponseWriter, r *http.Request)
- func (mux *Ngamux) Use(middlewares ...MiddlewareFunc)
- func (mux *Ngamux) With(middlewares ...MiddlewareFunc) *Ngamux
- type Request
- func (r Request) FormFile(key string, maxFileSize ...int64) (*multipart.FileHeader, error)
- func (r Request) FormValue(key string, fallback ...string) string
- func (r *Request) IsLocalhost() bool
- func (r Request) JSON(store any) error
- func (r *Request) Locals(key any, value ...any) any
- func (r Request) Params(key string) string
- func (r Request) Query(key string, fallback ...string) string
- type Response
- type Route
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorNotFound is errors object when searching failure ErrorNotFound = errors.New("not found") // ErrorMethodNotAllowed is errors object when there access to invalid method ErrorMethodNotAllowed = errors.New("method not allowed") )
Functions ¶
func WithErrorHandler ¶ added in v1.1.0
WithErrorHandler returns function that adds GlobalErrorHandler into config
func WithLogLevel ¶ added in v1.4.0
WithLogLevel returns function that adds GlobalErrorHandler into config
func WithTrailingSlash ¶ added in v1.1.0
func WithTrailingSlash() func(*Config)
WithTrailingSlash returns function that adds RemoveTrailingSlash into config
Types ¶
type Handler ¶ added in v1.0.1
type Handler func(rw http.ResponseWriter, r *http.Request) error
Handler describe function handler
type KeyContext ¶
type KeyContext int
KeyContext describe key type for ngamux context
const ( // KeyContextParams is key context for url params KeyContextParams KeyContext = 1 << iota )
type MiddlewareFunc ¶
MiddlewareFunc describe middleware function
func WithMiddlewares ¶
func WithMiddlewares(middleware ...MiddlewareFunc) MiddlewareFunc
WithMiddlewares returns single middleware from multiple middleware
type Ngamux ¶
type Ngamux struct {
// contains filtered or unexported fields
}
Ngamux describe structure of ngamux object
func (*Ngamux) Group ¶
func (mux *Ngamux) Group(url string, middlewares ...MiddlewareFunc) *Ngamux
Group returns new nested ngamux object
func (*Ngamux) ServeHTTP ¶
func (mux *Ngamux) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP run ngamux router matcher
func (*Ngamux) Use ¶
func (mux *Ngamux) Use(middlewares ...MiddlewareFunc)
Use register global middleware
func (*Ngamux) With ¶ added in v1.1.0
func (mux *Ngamux) With(middlewares ...MiddlewareFunc) *Ngamux
With register middlewares and returns router
type Request ¶ added in v1.3.0
Request define single request manager
func (*Request) IsLocalhost ¶ added in v1.4.0
IsLocalhost returns true if hostname is localhost or 127.0.0.1
func (Request) JSON ¶ added in v1.3.0
JSON get json data from request body and store to variable reference
func (*Request) Locals ¶ added in v1.3.0
Locals needs key and optional value It returns any if only key and no value given It insert value to context if key and value is given
type Response ¶ added in v1.2.0
type Response struct { http.ResponseWriter // contains filtered or unexported fields }
Response define single response manager
func Res ¶ added in v1.2.0
func Res(rw http.ResponseWriter) *Response
Res needs http.ResponseWriter and returns *Response object
func (*Response) Json ¶ added in v1.6.0
Json write application/json data with json encoded string as response body