Documentation ¶
Index ¶
- Constants
- Variables
- type BadRequestError
- type Handler
- type Middleware
- type Params
- type Req
- func (r *Req) DecodeJSON(dst interface{}) error
- func (r *Req) FormInt(key string) int
- func (r *Req) FormInt32(key string) int32
- func (r *Req) FormInt64(key string) int64
- func (r *Req) Int(param string) int
- func (r *Req) Int32(param string) int32
- func (r *Req) Int64(param string) int64
- func (r *Req) Param(param string) string
- func (r *Req) SSEStream(ctx context.Context, resp *Resp) (*SSEStream, error)
- func (r *Req) WebSocket(ctx context.Context, resp *Resp) (*WebSocket, error)
- type Resp
- func (r *Resp) Attachment(req *Req, name string, modtime time.Time, content io.ReadSeeker) error
- func (r *Resp) Error(text string, status int) error
- func (r *Resp) Error404(text string) error
- func (r *Resp) Error500(text string) error
- func (r *Resp) ErrorBadRequest() error
- func (r *Resp) ErrorInternal() error
- func (r *Resp) File(req *Req, name string, modtime time.Time, content io.ReadSeeker) error
- func (r *Resp) JSON(src interface{}) error
- func (r *Resp) JSONBytes(bytes []byte, status int) error
- func (r *Resp) JSONStatus(v interface{}, status int) error
- func (r *Resp) SetContentLength(length int64)
- func (r *Resp) SetContentType(ctype string)
- func (r *Resp) SetCookie(cookie *http.Cookie)
- func (r *Resp) Text(text string) error
- func (r *Resp) TextStatus(text string, status int) error
- func (r *Resp) Write(b []byte) (int, error)
- func (r *Resp) WriteHeader(status int)
- type Route
- func (r *Route) ALL(pattern string, h Handler)
- func (r *Route) Add(pattern string, child *Route)
- func (r *Route) DELETE(pattern string, h Handler)
- func (r *Route) GET(pattern string, h Handler)
- func (r *Route) HEAD(pattern string, h Handler)
- func (r *Route) Handler(method string, p string, h Handler)
- func (r *Route) Match(method string, path string) ([]Middleware, Handler, Params, error)
- func (r *Route) Middleware(pattern string, m Middleware)
- func (r *Route) POST(pattern string, h Handler)
- func (r *Route) PUT(pattern string, h Handler)
- func (r *Route) Resolve(path string) ([]*Route, Params, error)
- func (r *Route) Static(pattern string, dir http.Dir)
- type Router
- func (r *Router) ALL(p string, h Handler)
- func (r *Router) Add(p string, child *Route)
- func (r *Router) Close() <-chan struct{}
- func (r *Router) Closed() <-chan struct{}
- func (r *Router) DELETE(p string, h Handler)
- func (r *Router) GET(p string, h Handler)
- func (r *Router) HEAD(p string, h Handler)
- func (r *Router) Handler(m string, p string, h Handler)
- func (r *Router) Middleware(p string, m Middleware)
- func (r *Router) OnSSEStreamClosed(s *SSEStream)
- func (r *Router) OnSSEStreamOpened(s *SSEStream)
- func (r *Router) OnWebSocketClosed(ws *WebSocket)
- func (r *Router) OnWebSocketOpened(ws *WebSocket)
- func (r *Router) POST(p string, h Handler)
- func (r *Router) PUT(p string, h Handler)
- func (r *Router) ServeHTTP(w http.ResponseWriter, httpReq *http.Request)
- func (r *Router) Static(p string, root http.Dir)
- type SSEStream
- type SSEStreamListener
- type WebSocket
- func (ws *WebSocket) Close() <-chan struct{}
- func (ws *WebSocket) Closed() <-chan struct{}
- func (ws *WebSocket) Incoming() <-chan []byte
- func (ws *WebSocket) Outgoing() chan<- []byte
- func (ws *WebSocket) Send(ctx context.Context, text string)
- func (ws *WebSocket) SendJSON(ctx context.Context, v interface{}) error
- type WebSocketListener
Constants ¶
View Source
const ( ALL = "" HEAD = "HEAD" GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" )
Variables ¶
View Source
var ( ErrRouteNotFound = errors.New("router: Route not found") ErrMethodNotAllowed = errors.New("router: Method not allowed") )
Functions ¶
This section is empty.
Types ¶
type BadRequestError ¶
type BadRequestError struct {
Text string
}
func NewBadRequestError ¶
func NewBadRequestError(text string) BadRequestError
func (BadRequestError) Error ¶
func (r BadRequestError) Error() string
type Handler ¶
func NewStaticHandler ¶
NewStaticHandler returns a handler which serves static files from a given directory.
type Middleware ¶
type Req ¶
func (*Req) DecodeJSON ¶
DecodeJSON decodes a JSON body into a given destination.
type Resp ¶
type Resp struct { Router *Router http.ResponseWriter Status int TotalBytes int64 }
func (*Resp) Attachment ¶
Attachment serves a file as a downloadable attachment.
func (*Resp) ErrorBadRequest ¶
func (*Resp) ErrorInternal ¶
func (*Resp) JSON ¶
JSON serves an OK JSON response, returns an error on JSON encoding errors, when no response is written yet.
func (*Resp) JSONStatus ¶
JSONStatus returns a JSON response, returns an error on JSON encoding errors, when no response is written yet.
func (*Resp) SetContentLength ¶
func (*Resp) SetContentType ¶
func (*Resp) WriteHeader ¶
type Route ¶
type Route struct { Name string Param string Middle []Middleware Handlers map[string]Handler // map[method]Handler Children map[string]*Route // map[pattern]*Route }
Route is a linked tree of routes with handlers and middleware.
func (*Route) Middleware ¶
func (r *Route) Middleware(pattern string, m Middleware)
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) Middleware ¶
func (r *Router) Middleware(p string, m Middleware)
func (*Router) OnSSEStreamClosed ¶
func (*Router) OnSSEStreamOpened ¶
func (*Router) OnWebSocketClosed ¶
func (*Router) OnWebSocketOpened ¶
type SSEStream ¶
type SSEStream struct {
// contains filtered or unexported fields
}
func NewSSEStream ¶
type SSEStreamListener ¶
type WebSocket ¶
type WebSocket struct {
// contains filtered or unexported fields
}
func NewWebSocket ¶
type WebSocketListener ¶
Click to show internal directories.
Click to hide internal directories.