Documentation
¶
Index ¶
- func DefaultErrHandlerFunc(err error, w http.ResponseWriter)
- type ErrHandlerFunc
- type HTTPError
- type HandlerFunc
- type HelperResponseWriter
- func (rw *HelperResponseWriter) Flush()
- func (rw *HelperResponseWriter) HTML(statusCode int, html string) error
- func (rw *HelperResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (rw *HelperResponseWriter) JSON(statusCode int, data any) error
- func (rw *HelperResponseWriter) Push(target string, opts *http.PushOptions) error
- func (rw *HelperResponseWriter) String(statusCode int, s string) error
- func (rw *HelperResponseWriter) Unwrap() http.ResponseWriter
- func (rw *HelperResponseWriter) XML(statusCode int, data any, indent string) error
- type Map
- type MiddlewareFunc
- type RouteMiddlewareFunc
- type ServeMux
- func (sm *ServeMux) Connect(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
- func (sm *ServeMux) Delete(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
- func (sm *ServeMux) Get(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
- func (sm *ServeMux) Group(prefix string) *ServeMux
- func (sm *ServeMux) HandleFunc(pattern string, h HandlerFunc)
- func (sm *ServeMux) Head(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
- func (sm *ServeMux) Options(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
- func (sm *ServeMux) Patch(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
- func (sm *ServeMux) Post(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
- func (sm *ServeMux) Put(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
- func (sm *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (sm *ServeMux) Trace(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
- func (sm *ServeMux) Use(m ...MiddlewareFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrHandlerFunc ¶
func DefaultErrHandlerFunc(err error, w http.ResponseWriter)
default centrailzed error handling function. only the *HTTPError will triger error response.
Types ¶
type ErrHandlerFunc ¶
type ErrHandlerFunc func(err error, w http.ResponseWriter)
centralized error handling function type.
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request) error
HandlerFunc defines the function signature for a handler. It returns an error, which is used for centralized error handling.
func Adator ¶
func Adator(fn func(w http.ResponseWriter, r *http.Request)) HandlerFunc
type HelperResponseWriter ¶
type HelperResponseWriter struct {
http.ResponseWriter
}
A built-in type, used only to record the StatusCode and quickly send responses.
func NewHelperRW ¶
func NewHelperRW(w http.ResponseWriter) *HelperResponseWriter
func (*HelperResponseWriter) HTML ¶
func (rw *HelperResponseWriter) HTML(statusCode int, html string) error
send html
func (*HelperResponseWriter) Hijack ¶
func (rw *HelperResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
implement http.Hijacker
func (*HelperResponseWriter) JSON ¶
func (rw *HelperResponseWriter) JSON(statusCode int, data any) error
send json
func (*HelperResponseWriter) Push ¶
func (rw *HelperResponseWriter) Push(target string, opts *http.PushOptions) error
implement http.Pusher
func (*HelperResponseWriter) String ¶
func (rw *HelperResponseWriter) String(statusCode int, s string) error
send string
func (*HelperResponseWriter) Unwrap ¶
func (rw *HelperResponseWriter) Unwrap() http.ResponseWriter
get the wrapped ResponseWriter
type MiddlewareFunc ¶
Middleware function signatrue
type RouteMiddlewareFunc ¶
type RouteMiddlewareFunc func(next HandlerFunc) HandlerFunc
type ServeMux ¶
type ServeMux struct {
http.ServeMux
ErrHandlerFunc ErrHandlerFunc
// contains filtered or unexported fields
}
ServeMux embeds http.ServeMux
func (*ServeMux) Connect ¶
func (sm *ServeMux) Connect(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
func (*ServeMux) Delete ¶
func (sm *ServeMux) Delete(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
func (*ServeMux) Get ¶
func (sm *ServeMux) Get(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
Here is the helper function:
func (*ServeMux) HandleFunc ¶
func (sm *ServeMux) HandleFunc(pattern string, h HandlerFunc)
To rewrite the HandleFunc function signature
func (*ServeMux) Head ¶
func (sm *ServeMux) Head(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
func (*ServeMux) Options ¶
func (sm *ServeMux) Options(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
func (*ServeMux) Patch ¶
func (sm *ServeMux) Patch(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
func (*ServeMux) Post ¶
func (sm *ServeMux) Post(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
func (*ServeMux) Put ¶
func (sm *ServeMux) Put(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
func (*ServeMux) ServeHTTP ¶
func (sm *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
To rewrite the ServeHTTP function
func (*ServeMux) Trace ¶
func (sm *ServeMux) Trace(path string, h HandlerFunc, m ...RouteMiddlewareFunc)
func (*ServeMux) Use ¶
func (sm *ServeMux) Use(m ...MiddlewareFunc)
Use adds middleware for the mux.
Directories
¶
| Path | Synopsis |
|---|---|
|
_example
|
|
|
hello_world
command
|
|
|
Declaration: The middleware package is copied from chi/v5/middleware.
|
Declaration: The middleware package is copied from chi/v5/middleware. |