Documentation ¶
Index ¶
- Variables
- func Delete(path string, handler HandlerType)
- func Exception(ctx context.Context) interface{}
- func Get(path string, handler HandlerType)
- func Handle(method, path string, handler HandlerType)
- func Handler() http.Handler
- func Head(path string, handler HandlerType)
- func NotFound(handler HandlerType)
- func Options(path string, handler HandlerType)
- func Param(ctx context.Context, name string) string
- func Patch(path string, handler HandlerType)
- func Post(path string, handler HandlerType)
- func Put(path string, handler HandlerType)
- func Reset()
- func Serve()
- func Use(path string, mw MiddlewareType)
- type ContextHandler
- type HandlerFunc
- type HandlerType
- type Middleware
- type MiddlewareType
Constants ¶
This section is empty.
Variables ¶
var ( // Context is the root "god object" from which every request's context will derive Context = context.Background() // PanicHandler will, if set, be called on panics. // You can use kami.Exception(ctx) within the panic handler to get panic details. PanicHandler HandlerType // LogHandler will, if set, wrap every request and be called at the very end. LogHandler func(context.Context, mutil.WriterProxy, *http.Request) )
Functions ¶
func Delete ¶
func Delete(path string, handler HandlerType)
Delete registers a DELETE handler under the given path.
func Exception ¶
Exception gets the "v" in panic(v). The panic details. Only PanicHandler will receive a context you can use this with.
func Get ¶
func Get(path string, handler HandlerType)
Get registers a GET handler under the given path.
func Handle ¶
func Handle(method, path string, handler HandlerType)
Handle registers an arbitrary method handler under the given path.
func Head ¶
func Head(path string, handler HandlerType)
Head registers a HEAD handler under the given path.
func NotFound ¶
func NotFound(handler HandlerType)
NotFound registers a special handler for unregistered (404) paths. If handle is nil, use the default http.NotFound behavior.
func Options ¶
func Options(path string, handler HandlerType)
Options registers a OPTIONS handler under the given path.
func Param ¶
Param returns a request URL parameter, or a blank string if it doesn't exist. For example, with the path /v2/papers/:page use kami.Param(ctx, "page") to access the :page variable.
func Patch ¶
func Patch(path string, handler HandlerType)
Patch registers a PATCH handler under the given path.
func Post ¶
func Post(path string, handler HandlerType)
Post registers a POST handler under the given path.
func Put ¶
func Put(path string, handler HandlerType)
Put registers a PUT handler under the given path.
func Reset ¶
func Reset()
Reset changes the root Context to context.Background(). It removes every handler and all middleware.
func Serve ¶
func Serve()
Serve starts kami with reasonable defaults. It works (exactly) like Goji, looking for Einhorn, the bind flag, GOJI_BIND...
func Use ¶
func Use(path string, mw MiddlewareType)
Use registers middleware to run for the given path. Middleware with be executed hierarchically, starting with the least specific path. Middleware will be executed in order of registration. You may use wildcards in the path. Wildcard middleware will be run last, after all hierarchical middleware has run.
Adding middleware is not threadsafe.
WARNING: kami middleware is run in sequence, but standard middleware is chained; middleware that expects its code to run after the next handler, such as standard loggers and panic handlers, will not work as expected. Use kami.LogHandler and kami.PanicHandler instead. Standard middleware that does not call the next handler to stop the request is supported.
Types ¶
type ContextHandler ¶
type ContextHandler interface {
ServeHTTPContext(context.Context, http.ResponseWriter, *http.Request)
}
ContextHandler is like http.Handler but supports context.
type HandlerFunc ¶
HandlerFunc is like http.HandlerFunc with context.
func (HandlerFunc) ServeHTTPContext ¶
func (h HandlerFunc) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request)
type HandlerType ¶
type HandlerType interface{}
HandlerType is the type of Handlers and types that kami internally converts to ContextHandler. In order to provide an expressive API, this type is an alias for interface{} that is named for the purposes of documentation, however only the following concrete types are accepted:
- types that implement http.Handler
- types that implement ContextHandler
- func(http.ResponseWriter, *http.Request)
- func(context.Context, http.ResponseWriter, *http.Request)
type Middleware ¶
Middleware is a function that takes the current request context and returns a new request context. You can use middleware to build your context before your handler handles a request. As a special case, middleware that returns nil will halt middleware and handler execution (LogHandler will still run).
type MiddlewareType ¶
type MiddlewareType interface{}
MiddlewareType represents types that kami can convert to Middleware. kami will try its best to convert standard, non-context middleware. See the Use function for important information about how kami middleware is run. The following concrete types are accepted:
- Middleware
- func(context.Context, http.ResponseWriter, *http.Request) context.Context
- func(http.Handler) http.Handler [will run sequentially, not in a chain]
- func(http.ContextHandler) http.ContextHandler [will run sequentially, not in a chain]