Documentation ¶
Index ¶
- Constants
- Variables
- func GetParam(ctx *RequestCtx, key string) (bytes.Bytes, bool)
- type Body
- type ConnCtx
- type Handler
- type HandlerFunc
- type Mux
- type NopReadCloser
- type NopReader
- type RequestCtx
- func (ctx *RequestCtx) Deadline() (deadline time.Time, ok bool)
- func (ctx *RequestCtx) Done() <-chan struct{}
- func (ctx *RequestCtx) Err() error
- func (ctx *RequestCtx) LocalAddr() net.Addr
- func (ctx *RequestCtx) RemoteAddr() net.Addr
- func (ctx *RequestCtx) URI() *uri.URI
- func (ctx *RequestCtx) Value(key interface{}) interface{}
- func (ctx *RequestCtx) WithCancel() func()
- func (ctx *RequestCtx) WithDeadline(deadline time.Time)
- func (ctx *RequestCtx) WithTimeout(timeout time.Duration)
- func (ctx *RequestCtx) WithValue(key interface{}, value interface{})
- type Server
- func (srv *Server) ListenAndServe(network, addr string) error
- func (srv *Server) ListenAndServeTLS(network, addr, certFile, keyFile string) error
- func (srv *Server) Serve(ln net.Listener) error
- func (srv *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error
- func (srv *Server) Shutdown() error
Constants ¶
const ( // DefaultReadBufSize is the default Server read buffer size DefaultReadBufSize = 4096 // DefaultWriteBufSize is the default Serve write buffer size DefaultWriteBufSize = 4096 )
Variables ¶
var ErrBodyClosed = errors.New("fastnet: read on closed body")
ErrBodyClosed is returned if a read is attempted on a closed BodyReader
var ErrNegativeBody = errors.New("fastnet: negative body size")
ErrNegativeBody is returned if a read is attempted on a BodyReader with negative body size
var ErrServerClosed = errors.New("fastnet: server closed")
ErrServerClosed is returned by Listen routines on Server.Shutdown()
Functions ¶
func GetParam ¶
func GetParam(ctx *RequestCtx, key string) (bytes.Bytes, bool)
GetParam attempts to fetch path parameter set by fastnet.Mux from the RequestCtx
Types ¶
type Body ¶ added in v1.1.0
type Body struct {
// contains filtered or unexported fields
}
Body provides a means of reading a fixed-size request body
type ConnCtx ¶
type ConnCtx struct {
// contains filtered or unexported fields
}
ConnCtx is a structure used in building and preparing a RequestCtx for a Handler function
func (*ConnCtx) Ctx ¶
func (cc *ConnCtx) Ctx() *RequestCtx
Ctx returns the RequestCtx associated with this ConnCtx
func (*ConnCtx) OnDone ¶
func (cc *ConnCtx) OnDone(fn func())
OnDone allows you to add a function hook that is called when the ConnCtx is done
type Handler ¶
type Handler interface {
Serve(*RequestCtx)
}
Handler defines a handler for incoming requests
type HandlerFunc ¶
type HandlerFunc func(*RequestCtx)
HandlerFunc is a simple adapter to allow the use of functions as Handlers
func (HandlerFunc) Serve ¶
func (h HandlerFunc) Serve(ctx *RequestCtx)
type Mux ¶
type Mux struct { // RootHandler is the default handler used when no path handler is found RootHandler Handler // PanicHandler is used to catch any panics during other handler execution PanicHandler func(*RequestCtx, interface{}) // contains filtered or unexported fields }
func (*Mux) Serve ¶
func (m *Mux) Serve(ctx *RequestCtx)
Serve attempts to serve the supplied RequestCtx using a set Handler, else uses the RootHandler
type NopReadCloser ¶
NopReadCloser wraps an io.Reader to support io.Closer
func (*NopReadCloser) Close ¶
func (rc *NopReadCloser) Close() error
type RequestCtx ¶
type RequestCtx struct {
// contains filtered or unexported fields
}
RequestCtx @TODO
func (*RequestCtx) Deadline ¶
func (ctx *RequestCtx) Deadline() (deadline time.Time, ok bool)
Deadline implements context.Context .Deadline().
func (*RequestCtx) Done ¶
func (ctx *RequestCtx) Done() <-chan struct{}
Done implements context.Context .Done().
func (*RequestCtx) LocalAddr ¶
func (ctx *RequestCtx) LocalAddr() net.Addr
LocalAddr returns the local network address.
func (*RequestCtx) RemoteAddr ¶
func (ctx *RequestCtx) RemoteAddr() net.Addr
RemoteAddr returns the remote network address.
func (*RequestCtx) URI ¶
func (ctx *RequestCtx) URI() *uri.URI
URI returns the parsed URI of this request context.
func (*RequestCtx) Value ¶
func (ctx *RequestCtx) Value(key interface{}) interface{}
Value implements context.Context .Value().
func (*RequestCtx) WithCancel ¶ added in v1.1.0
func (ctx *RequestCtx) WithCancel() func()
WithCancel returns a cancel function for this context.
func (*RequestCtx) WithDeadline ¶ added in v1.1.0
func (ctx *RequestCtx) WithDeadline(deadline time.Time)
WithDeadline updates the context deadline to supplied time, time <= Now() does nothing.
func (*RequestCtx) WithTimeout ¶ added in v1.2.0
func (ctx *RequestCtx) WithTimeout(timeout time.Duration)
WithTimeout updates the context deadline to now+timeout, time <= Now() does nothing.
func (*RequestCtx) WithValue ¶ added in v1.1.0
func (ctx *RequestCtx) WithValue(key interface{}, value interface{})
WithValue sets the supplied key-value pair in context data.
type Server ¶
type Server struct { // Env allows setting custom server implementation variables which are then // accessible via the ConnCtx.Srv() within the ConnHandler Env map[string]interface{} // ReadTimeout is the total time allowed to the read the entire request. // Can also be used as just an initial timeout if you set the read deadline // again during ConnHandler to push forward the deadline for body reads. Set // to zero for no read timeout ReadTimeout time.Duration // WriteTimeout is the maximum duration before timing out response writes. // This is set once before passing to ConnHandler in case of required error // response, and once before Handler for the main request handling. Set to // zero for no write timeout WriteTimeout time.Duration // ConnHandler is the new connection handler function, a ConnCtx is passed // here just after accepting the new connection. Here you should implement // your protocol specific request parsing logic ConnHandler func(*ConnCtx) error // ReqHandler is the handler for processing incoming requests Handler Handler // LogOut is the default server error log output location LogOut io.Writer // contains filtered or unexported fields }