render

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRender

func MustRender(r Renderer, w io.Writer, value any)

MustRender calls `r.Render()` and panics if a non-nil error is returned

func WithCtx

func WithCtx(ctx context.Context, r Renderer) context.Context

WithCtx returns a copy of ctx with r associated.

Types

type JSON

type JSON struct{}

JSON is a renderers that marshals the value to JSON

func (JSON) Render

func (j JSON) Render(w io.Writer, value any) error

Render implements the Renderer interface

type Print

type Print struct{}

Print prints the value with the default format for the value's type.

func (Print) Render

func (p Print) Render(w io.Writer, value any) error

Render implements the Renderer interface

type Renderer

type Renderer interface {
	Render(w io.Writer, value any) error
}

A Render formats the provided value and outputs it to the writer.

var DefaultContextRenderer Renderer

func Ctx

func Ctx(ctx context.Context) Renderer

Ctx returns the Renderer associated with the ctx. If no logger is associated, DefaultContextRenderer is returned, unless DefaultContextRenderer is nil, in which case a Print renderer is returned.

type Template

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

Template renders a template with the provided value

func NewTemplate

func NewTemplate(tmpl string) *Template

NewTemplate creates a Template with the given string template

func (*Template) Render

func (t *Template) Render(w io.Writer, value any) error

Render implements the Renderer interface

Jump to

Keyboard shortcuts

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