rbview

package module
v0.0.0-...-dbdc49b Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: MIT Imports: 9 Imported by: 0

README

Backlogs

  • COULD add a top level Render that either uses the view configured in the context, or a global view if non is available. BUT 1: view is not request scoped, BUT 2: globals are an anti-pattern
  • COULD add a renderer for the "session" that "renders" by saving the session to the response. It must be placed before regular renderers.
  • SHOULD move all template stuff to rbtemplate
  • COULD allow for url path extensions to determine which encoder to use
  • SHOULD do render logging on request scope if possible
  • SHOULD test error paths, after having a nice error type to work with
  • COULD add middleware that returns a request/response scoped render from the context
  • COULD add a convenient method to render a redirect

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JSONEncoder = fx.Annotated{
	Target: NewJSON,
	Group:  "rb.encoder",
}
View Source
var TemplateEncoder = fx.Annotated{
	Target: NewTemplate,
	Group:  "rb.encoder",
}

Functions

This section is empty.

Types

type Conf

type Conf struct {
	EncoderOrder []string `env:"RB_VIEW_ENCODER_ORDER" envSeparator:","`
}

Conf configures the binder

func ParseConf

func ParseConf() (cfg Conf, err error)

ParseConf parses the env

type Encoder

type Encoder interface {
	MIME() string
	Encode(w http.ResponseWriter, r *http.Request, v interface{}, o Options) error
}

func NewJSON

func NewJSON() Encoder

func NewTemplate

func NewTemplate(tmpl *template.Template) Encoder

type JSON

type JSON struct{}

func (*JSON) Encode

func (e *JSON) Encode(w http.ResponseWriter, r *http.Request, v interface{}, o Options) error

func (*JSON) MIME

func (e *JSON) MIME() string

type Option

type Option func(*Options)

func Template

func Template(name string) Option

type Options

type Options struct {
	TemplateName string
}

type Params

type Params struct {
	fx.In
	Encoders []Encoder `group:"rb.encoder"`
}

Params configures dependencies binding dependencies

type Tmpl

type Tmpl struct {
	// contains filtered or unexported fields
}

func (*Tmpl) Encode

func (e *Tmpl) Encode(w http.ResponseWriter, r *http.Request, v interface{}, o Options) error

func (*Tmpl) MIME

func (e *Tmpl) MIME() string

type V

type V interface {
	Render(w http.ResponseWriter, r *http.Request, d interface{}, opts ...Option) error
}

V is the view interface

func New

func New(logs *zap.Logger, cfg Conf, p Params) (V, error)

type View

type View struct {
	// contains filtered or unexported fields
}

func (*View) Render

func (v *View) Render(w http.ResponseWriter, r *http.Request, d interface{}, opts ...Option) (err error)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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