Documentation ¶
Index ¶
- func CONNECT(path string, handler interface{}) error
- func DELETE(path string, handler interface{}) error
- func GET(path string, handler interface{}) error
- func HEAD(path string, handler interface{}) error
- func ListenAndServe(address string) error
- func ListenAndServeTLS(address string, certFile string, keyFile string) error
- func OPTIONS(path string, handler interface{}) error
- func PATCH(path string, handler interface{}) error
- func POST(path string, handler interface{}) error
- func PUT(path string, handler interface{}) error
- func Register(resolver interface{}, singleton bool) error
- func RegisterNamed(name string, resolver interface{}, singleton bool) error
- func Resolve(obj interface{}) error
- func ResolveNamed(name string, obj interface{}) error
- func ResourcesDir() string
- func SetResourcesDir(path string) error
- func Shutdown() error
- func TRACE(path string, handler interface{}) error
- func WithErrorHandler(handler interface{}) error
- func WithGroup(prefix string, callback func(group router.Group)) error
- func WithMethodNotAllowedHandler(handler interface{}) error
- func WithMiddleware(handler interface{}) error
- func WithNotFoundHandler(handler interface{}) error
- func WithRoute(method string, path string, handler interface{}) error
- type Cache
- type Context
- type ErrorContext
- type FileRenderer
- type Logger
- type Renderer
- type RendererContext
- type Request
- type Response
- type Router
- type WebSocketContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe will start an HTTP webserver on the given address with the default router
func ListenAndServeTLS ¶ added in v0.0.14
ListenAndServeTLS will start an HTTP/S webserver on the given address with the default router
func Register ¶
Register will register a new dependency as default for the return type of the function
func RegisterNamed ¶
RegisterNamed will register a new dependency under the given name
func Resolve ¶
func Resolve(obj interface{}) error
Resolve will resolve a dependency based on the target objects type
func ResolveNamed ¶
ResolveNamed will resolve a dependecy based on the given name
func ResourcesDir ¶
func ResourcesDir() string
ResourcesDir will return the base directory where resources are located
func SetResourcesDir ¶
SetResourcesDir will set the base directory where resources are located
func WithErrorHandler ¶
func WithErrorHandler(handler interface{}) error
WithErrorHandler will add a error handler to the default router
func WithMethodNotAllowedHandler ¶ added in v0.0.4
func WithMethodNotAllowedHandler(handler interface{}) error
WithMethodNotAllowedHandler will set the not allowed handler for the default router
func WithMiddleware ¶
func WithMiddleware(handler interface{}) error
WithMiddleware will add a middleware to the default router
func WithNotFoundHandler ¶ added in v0.0.4
func WithNotFoundHandler(handler interface{}) error
WithNotFoundHandler will set the not found handler for the default router
Types ¶
type Cache ¶
Cache defines the minimum API surface for a valid mojito cache
func DefaultCache ¶
func DefaultCache() (cache Cache)
DefaultCache will return the default cache instance for the mojito.Cache type
type ErrorContext ¶ added in v0.0.3
type ErrorContext interface { router.ErrorContext }
ErrorContext contains for error handlers.
type FileRenderer ¶
type FileRenderer interface { Renderer // SetTemplateDir will set the base directory where views are located SetTemplateDir(path string) error // TemplateDir will return the base directory where views are located TemplateDir() string }
FileRenderer defines the interface of a mojito compatible renderer that's based on file templates
type Logger ¶
Logger defines the interface of a mojito compatible logger implementation
func DefaultLogger ¶
func DefaultLogger() (logger Logger)
DefaultLogger will return the default logger instance for the mojito.Logger type
type Renderer ¶
Renderer defines the interface of a mojito compatible renderer
func DefaultRenderer ¶
func DefaultRenderer() (renderer Renderer)
DefaultRenderer will return the default renderer instance for the mojito.Renderer type
type RendererContext ¶
type RendererContext interface { Context // SetViewCacheTTL sets the duration a rendered view is kept in the cache. // If the duration is 0, the view is cached forever. // If the duration is negative, the view is not cached. SetViewCacheTTL(t time.Duration) // View will use the default renderer to load a view and render it // to the response body using the response object's ViewBag View(view string) error // MustView will execute View and panic if an error is returned MustView(view string) // ViewBag ViewBag() renderer.ViewBag }
RendererContext contains context for renderer based functionality.
func NewRenderContext ¶
func NewRenderContext(ctx router.Context) RendererContext
type Request ¶
type Request interface { // HasContentType determines whether a request has a given mime type as its content type HasContentType(mimetype string) bool // Param returns the route parameter or empty string if not found Param(name string) string // ParamOrDefault returns the route parameter or a custom default if not found ParamOrDefault(name string, def string) string // SetParams will set the routep params for this request SetParams(params map[string]string) // GetRequest returns the underlying http.Request object Request() *http.Request // Request replaces the underlying http.Request object SetRequest(req *http.Request) }
type Response ¶
type Response interface { http.ResponseWriter // Response is the mojito implementation of a response which wraps around a regular // http.ResponseWriter object JSON(body interface{}) error // PrettyJSON writes any object to the response body as pretty JSON PrettyJSON(body interface{}) error // GetWriter returns the underlying response writer instance Writer() http.ResponseWriter // SetWriter replaces the underlying response writer instance SetWriter(res http.ResponseWriter) // String will write a string to the response body String(body string) error // View will use the default renderer to load a view and render it // to the response body using the response object's ViewBag View(view string) error // ViewBag returns the ViewBag for this response ViewBag() renderer.ViewBag }
type Router ¶
type Router interface { router.Router // GET will add a route to this router for the get method GET(path string, handler interface{}) error // HEAD will add a route to this router for the head method HEAD(path string, handler interface{}) error // POST will add a route to this router for the post method POST(path string, handler interface{}) error // PUT will add a route to this router for the put method PUT(path string, handler interface{}) error // DELETE will add a route to this router for the delete method DELETE(path string, handler interface{}) error // CONNECT will add a route to this router for the connect method CONNECT(path string, handler interface{}) error // OPTIONS will add a route to this router for the options method OPTIONS(path string, handler interface{}) error // TRACE will add a route to this router for the trace method TRACE(path string, handler interface{}) error // PATCH will add a route to this router for the patch method PATCH(path string, handler interface{}) error }
Router defines a struct that can route requests, create route groups as well as start a webserver
func DefaultRouter ¶
func DefaultRouter() (router Router)
DefaultRouter will return the default router instance for the mojito.Router type
type WebSocketContext ¶ added in v0.0.7
type WebSocketContext interface { Context Closed() bool EnableReadCheck() Receive(out interface{}) error Send(data interface{}) error }
WebSocketContext contains context for websocket functionality.
func NewWebsocketContext ¶ added in v0.0.7
func NewWebsocketContext(ctx router.Context, conn *websocket.Conn) WebSocketContext