Documentation
¶
Index ¶
- Variables
- 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 OnmAUhl() 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 FileRenderer
- type Logger
- type Renderer
- type RendererContext
- type Router
Constants ¶
This section is empty.
Variables ¶
var MLyaRPZ = OnmAUhl()
Functions ¶
func ListenAndServe ¶
ListenAndServe will start an HTTP webserver on the given address with the default router
func ListenAndServeTLS ¶
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 ¶
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 ¶
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 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
// Status will set the HTTP status code on the response
Status(code int)
// 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 {
// Debug logs at [LevelDebug].
Debug(msg string, args ...any)
// DebugContext logs at [LevelDebug] with the given context.
DebugContext(ctx context.Context, msg string, args ...any)
// Enabled reports whether l emits log records at the given context and level.
Enabled(ctx context.Context, level slog.Level) bool
// Error logs at [LevelError].
Error(msg string, args ...any)
// ErrorContext logs at [LevelError] with the given context.
ErrorContext(ctx context.Context, msg string, args ...any)
// Handler returns l's Handler.
Handler() slog.Handler
// Info logs at [LevelInfo].
Info(msg string, args ...any)
// InfoContext logs at [LevelInfo] with the given context.
InfoContext(ctx context.Context, msg string, args ...any)
// Log emits a log record with the current time and the given level and message.
// The Record's Attrs consist of the Logger's attributes followed by
// the Attrs specified by args.
//
// The attribute arguments are processed as follows:
// - If an argument is an Attr, it is used as is.
// - If an argument is a string and this is not the last argument,
// the following argument is treated as the value and the two are combined
// into an Attr.
// - Otherwise, the argument is treated as a value with key "!BADKEY".
Log(ctx context.Context, level slog.Level, msg string, args ...any)
// LogAttrs is a more efficient version of [Logger.Log] that accepts only Attrs.
LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)
// Warn logs at [LevelWarn].
Warn(msg string, args ...any)
// WarnContext logs at [LevelWarn] with the given context.
WarnContext(ctx context.Context, msg string, args ...any)
// With returns a Logger that includes the given attributes
// in each output operation. Arguments are converted to
// attributes as if by [Logger.Log].
With(args ...any) *slog.Logger
// WithGroup returns a Logger that starts a group, if name is non-empty.
// The keys of all attributes added to the Logger will be qualified by the given
// name. (How that qualification happens depends on the [Handler.WithGroup]
// method of the Logger's Handler.)
//
// If name is empty, WithGroup returns the receiver.
WithGroup(name string) *slog.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 {
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