mojito

package module
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 12 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

	// JSON writes any object to the response body as JSON
	JSON(body interface{}) error

	// PrettyJSON writes any object to the response body as pretty JSON
	PrettyJSON(body interface{}) error

	// ReadJSON reads the request body as JSON and unmarshals it into the given object
	ReadJSON(obj interface{}) error

	// ReadXML reads the request body as XML and unmarshals it into the given object
	ReadXML(obj interface{}) error

	// String will write a string to the response body
	String(body string) error
}

Context contains the request and response objects of a request.

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 {
	router.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 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

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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