mojito

package module
v0.0.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2022 License: MIT Imports: 15 Imported by: 10

README

PRs Welcome

Mojito is a super-modular, fast, opinion-less framework to bootstrap your next Go web project. It can be used for strict API-only purposes as well as server-side rendering.

SonarCloud Report


Features

CachingDependency InjectionLoggingMiddlewareRoutingTemplating

Documentation

Read our Documentation, check out the Project Website.

Icon made with Gopherize and flaticon.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CONNECT

func CONNECT(path string, handler interface{}) error

CONNECT will add a route to the default router for the connect method

func DELETE

func DELETE(path string, handler interface{}) error

DELETE will add a route to the default router for the delete method

func GET

func GET(path string, handler interface{}) error

GET will add a route to the default router for the get method

func HEAD(path string, handler interface{}) error

HEAD will add a route to the default router for the head method

func ListenAndServe

func ListenAndServe(address string) error

ListenAndServe will start an HTTP webserver on the given address with the default router

func ListenAndServeTLS added in v0.0.14

func ListenAndServeTLS(address string, certFile string, keyFile string) error

ListenAndServeTLS will start an HTTP/S webserver on the given address with the default router

func OPTIONS

func OPTIONS(path string, handler interface{}) error

OPTIONS will add a route to the default router for the options method

func PATCH

func PATCH(path string, handler interface{}) error

PATCH will add a route to the default router for the patch method

func POST

func POST(path string, handler interface{}) error

POST will add a route to the default router for the post method

func PUT

func PUT(path string, handler interface{}) error

PUT will add a route to the default router for the put method

func Register

func Register(resolver interface{}, singleton bool) error

Register will register a new dependency as default for the return type of the function

func RegisterNamed

func RegisterNamed(name string, resolver interface{}, singleton bool) error

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

func ResolveNamed(name string, obj interface{}) error

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

func SetResourcesDir(path string) error

SetResourcesDir will set the base directory where resources are located

func Shutdown

func Shutdown() error

Shutdown will gracefully shutdown the default router

func TRACE

func TRACE(path string, handler interface{}) error

TRACE will add a route to the default router for the trace method

func WithErrorHandler

func WithErrorHandler(handler interface{}) error

WithErrorHandler will add a error handler to the default router

func WithGroup

func WithGroup(prefix string, callback func(group router.Group)) error

WithGroup will create a new route group for the given prefix on 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

func WithRoute

func WithRoute(method string, path string, handler interface{}) error

WithRoute will add a new route with the given RouteMethod to the default router

Types

type Cache

type Cache interface {
	cache.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 Context

type Context interface {
	router.Context
}

Context contains the request and response objects of a request.

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

type Logger interface {
	logger.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

type Renderer interface {
	renderer.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

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL