renderer

package
v0.0.0-...-5c5b187 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2016 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UnmarshalFromRequest = NewUnmarshalFromRequest()

UnmarshalFromRequest - Unmarshals component using `UnmarshalFromQuery` on `GET` method and “ on `POST` method.

Functions

func CompileInContext

func CompileInContext(next xhandler.HandlerC) xhandler.HandlerC

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

func New(opts ...Option) xhandler.HandlerC

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

func NewRequestContext(ctx context.Context, req *http.Request) context.Context

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

func RenderInContext(next xhandler.HandlerC) xhandler.HandlerC

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

func WriteRendered(ctx context.Context, w http.ResponseWriter, r *http.Request)

WriteRendered - Writes rendered component from context to response writer. Depending on `Accept` header, it will write json or plain html body.

func WriteRenderedHTML

func WriteRenderedHTML(ctx context.Context, w http.ResponseWriter, r *http.Request)

WriteRenderedHTML - Writes rendered component from context to response writer.

func WriteRenderedJSON

func WriteRenderedJSON(ctx context.Context, w http.ResponseWriter, r *http.Request)

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.

func (*Handler) Construct

func (h *Handler) Construct(opts ...Option) (xhandler.HandlerC, error)

Construct - Constructs http handler.

type Option

type Option func(*webOptions)

Option - Sets web server handler options.

func WithAlwaysHTML

func WithAlwaysHTML(enable ...bool) Option

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

func WithDefaultTemplateContext(ctx template.Context) Option

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

func WithTimeout(t time.Duration) Option

WithTimeout - Sets API server request timeout.

func WithTracing

func WithTracing(enable ...bool) Option

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.

func (Route) String

func (route Route) String() string

String - Returns string representation of a route.

type Routes

type Routes map[Route]*Handler

Routes - Routes map.

func RoutesFromFile

func RoutesFromFile(filename string) (Routes, error)

RoutesFromFile - Reads routes from yaml file.

func (Routes) Construct

func (routes Routes) Construct(options ...Option) (xhandler.HandlerC, error)

Construct - Constructs http router.

func (Routes) ToStringMap

func (routes Routes) ToStringMap() (res map[string]*Handler)

ToStringMap - To map with string routes.

Jump to

Keyboard shortcuts

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