Documentation ¶
Index ¶
- Variables
- func CompileInContext(next xhandler.HandlerC) xhandler.HandlerC
- func ComponentMiddleware(c *components.Component) middlewares.Handler
- func New(opts ...Option) xhandler.HandlerC
- func NewRequestContext(ctx context.Context, req *http.Request) context.Context
- func NewUnmarshalFromRequest() middlewares.Handler
- func RenderInContext(next xhandler.HandlerC) xhandler.HandlerC
- func UnmarshalFromBody(methods ...string) middlewares.Handler
- func UnmarshalFromQuery(methods ...string) middlewares.Handler
- func WriteRendered(ctx context.Context, w http.ResponseWriter, r *http.Request)
- func WriteRenderedHTML(ctx context.Context, w http.ResponseWriter, r *http.Request)
- func WriteRenderedJSON(ctx context.Context, w http.ResponseWriter, r *http.Request)
- type Handler
- type Option
- func WithAlwaysHTML(enable ...bool) Option
- func WithComponentSetter(componentSetter middlewares.Handler) Option
- func WithDefaultTemplateContext(ctx template.Context) Option
- func WithMiddleware(m middlewares.Handler) Option
- func WithTemplateContextSetter(templateCtxSetter middlewares.Handler) Option
- func WithTimeout(t time.Duration) Option
- func WithTracing(enable ...bool) Option
- type Route
- type Routes
Constants ¶
This section is empty.
Variables ¶
var UnmarshalFromRequest = NewUnmarshalFromRequest()
UnmarshalFromRequest - Unmarshals component using `UnmarshalFromQuery` on `GET` method and “ on `POST` method.
Functions ¶
func CompileInContext ¶
CompileInContext - Compiles component from context. Stores result in context to be retrieved with `components.FromContext`.
func ComponentMiddleware ¶
func ComponentMiddleware(c *components.Component) middlewares.Handler
ComponentMiddleware - Creates a middleware that sets given component in ctx.
func New ¶
New - New renderer web server API handler. Context should have a compiler set with `compiler.NewContext`. To always render HTML instead of JSON on Accept `application/json` use `WithAlwaysHTML()` option.
Default options are:
- WithTimeout(time.Second * 15),
- WithComponentSetter(UnmarshalFromRequest()),
func NewRequestContext ¶
NewRequestContext - Creates a context with request. Created context exposes many values. Context request values are available under `request` namespace (raw request).
- `request` - HTTP Request (*http.Request)
- `request.host` - Alias for `request.url.host` (string)
- `request.method` - Request Method (string)
- `request.remote` - Request Remote address (string)
- `request.header` - Request Header (http.Header)
- `request.header.{key}` - Request Header value (string)
- `request.form` - Request Form (url.Values)
- `request.form.{key}` - Request Form value (string)
- `request.url` - Request URL (*url.URL)
- `request.url.host` - Request URL Host (*url.URL)
- `request.url.query` - Request URL Query (url.Values)
- `request.url.query.{key}` - Request URL Query value (string)
- `request.url.params` - Request URL Parameters (xmux.ParamHolder)
- `request.url.params.{key}` - Request URL Parameter value (string)
func NewUnmarshalFromRequest ¶
func NewUnmarshalFromRequest() middlewares.Handler
NewUnmarshalFromRequest - Unmarshals component using `UnmarshalFromQuery` on `GET` method and “ on `POST` method.
func RenderInContext ¶
RenderInContext - Renders compiled component from context. Stores result in context to be retrieved with `components.ContextRendered`.
func UnmarshalFromBody ¶
func UnmarshalFromBody(methods ...string) middlewares.Handler
UnmarshalFromBody - Unmarshals component from request bodyCompileInContext() on certain methods. Stores result in context to be retrieved with `components.FromContext`.
func UnmarshalFromQuery ¶
func UnmarshalFromQuery(methods ...string) middlewares.Handler
UnmarshalFromQuery - Unmarshals component from `json` query on certain methods. Stores result in context to be retrieved with `components.FromContext`.
func WriteRendered ¶
WriteRendered - Writes rendered component from context to response writer. Depending on `Accept` header, it will write json or plain html body.
func WriteRenderedHTML ¶
WriteRenderedHTML - Writes rendered component from context to response writer.
func WriteRenderedJSON ¶
WriteRenderedJSON - Writes rendered component from context to response writer.
Types ¶
type Handler ¶
type Handler struct { Component *components.Component `json:"component,omitempty" yaml:"component,omitempty"` Middlewares []*middlewares.Middleware `json:"middlewares,omitempty" yaml:"middlewares,omitempty"` }
Handler - Web route handler.
type Option ¶
type Option func(*webOptions)
Option - Sets web server handler options.
func WithAlwaysHTML ¶
WithAlwaysHTML - Responds with html only when enabled. Uses first parameter if any.
func WithComponentSetter ¶
func WithComponentSetter(componentSetter middlewares.Handler) Option
WithComponentSetter - Sets component reader HTTP request middleware.
func WithDefaultTemplateContext ¶
WithDefaultTemplateContext - Sets default template context. Template context is cloned on every request because it's used as a base.
func WithMiddleware ¶
func WithMiddleware(m middlewares.Handler) Option
WithMiddleware - Adds a middleware.
func WithTemplateContextSetter ¶
func WithTemplateContextSetter(templateCtxSetter middlewares.Handler) Option
WithTemplateContextSetter - Sets component template context setter HTTP request middleware.
func WithTimeout ¶
WithTimeout - Sets API server request timeout.
func WithTracing ¶
WithTracing - Enables tracing. Uses first parameter if any.
type Route ¶
type Route struct { Path string `json:"path,omitempty" yaml:"path,omitempty"` Method string `json:"method,omitempty" yaml:"method,omitempty"` }
Route - Web route.
type Routes ¶
Routes - Routes map.
func RoutesFromFile ¶
RoutesFromFile - Reads routes from yaml file.
func (Routes) ToStringMap ¶
ToStringMap - To map with string routes.