Documentation ¶
Index ¶
- func AddRoute[InT, OutT, AppCtxT any](s *Server[AppCtxT], route *Route[InT, OutT, AppCtxT])
- func IsVoid[T any]() bool
- type AppCtxInit
- type CORSHeaderMW
- type Config
- type ErrCode
- type Error
- type Middleware
- type RequestLoggerMW
- type Route
- type RouteHandler
- type Server
- type ServerCtx
- type ServerResponse
- type Void
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppCtxInit ¶
AppCtxInit is the signature for the function which initializes the application provided AppCtxT for every request.
type CORSHeaderMW ¶
CORSHeaderMW adds the headers required to bypass browsers' CORS policy.
func (CORSHeaderMW[AppCtxT]) Exec ¶
func (mw CORSHeaderMW[AppCtxT]) Exec( ctx *ServerCtx[AppCtxT], w http.ResponseWriter, r *http.Request, ) *Error
type Error ¶
type Error struct { Status int `json:"status_code"` Code ErrCode `json:"app_err_code"` Msg string `json:"message,omitempty"` Details string `json:"details,omitempty"` }
A more verbose way to return an error.
type Middleware ¶
type RequestLoggerMW ¶
type RequestLoggerMW[AppCtxT any] struct{}
RequestLoggerMW logs some information about a request (such as sender IP) when it is accepted by the server.
func (RequestLoggerMW[AppCtxT]) Exec ¶
func (mw RequestLoggerMW[AppCtxT]) Exec( ctx *ServerCtx[AppCtxT], w http.ResponseWriter, r *http.Request, ) *Error
type Route ¶
type Route[InT, OutT, AppCtxT any] struct { // should be one of http.Method{Get,Head,Post,Put,Patch} etc. Method string Pattern string Handler RouteHandler[InT, OutT, AppCtxT] Codec codec.Codec MwStack []Middleware[AppCtxT] }
type RouteHandler ¶
type RouteHandler[InT, OutT, AppCtxT any] func( ctx *ServerCtx[AppCtxT], req *InT, ) (resp *OutT, err error)
RouteHandler is the signature for routes registered with the server.
type Server ¶
type Server[AppCtxT any] struct { // contains filtered or unexported fields }
type ServerCtx ¶
type ServerCtx[AppCtxT any] struct { context.Ctx[AppCtxT] Pattern, Path, Method string PathVars map[string]string Response ServerResponse }
ServerCtx a context which is threaded through all route handlers by a Server, and is intended to contain information that the handlers might need about the request they are executing.
type ServerResponse ¶ added in v0.4.0
Click to show internal directories.
Click to hide internal directories.