template

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HexConversion

func HexConversion(v interface{}) []byte

HexConversion returns a hex-encoded string

func Int64ToDateString

func Int64ToDateString(v interface{}) []byte

Int64ToDateString returns the value as a RFC3339 date string. If the type isn't an int64 or *wrapperspb.Int64Value type it will return a blank

Types

type Builder

type Builder struct {
	TemplateString string
	Transforms     TransformFunctionMap
	Marshaler      JSONMarshaler
	Parameters     interface{}
}

Builder is an type to build and configure template instances.

func New

func New(templateString string) *Builder

New creates a new template builder

func (*Builder) Build

func (t *Builder) Build() (*Template, error)

Build builds and validates the template

func (*Builder) WithJSONMarshaler

func (t *Builder) WithJSONMarshaler(marshaler JSONMarshaler) *Builder

func (*Builder) WithParameters

func (t *Builder) WithParameters(params interface{}) *Builder

WithParameters sets the parameter type used for the template. When the structure is built it will use this parameter struct to validate the template

func (*Builder) WithTransforms

func (t *Builder) WithTransforms(transformMap TransformFunctionMap) *Builder

WithTransforms modifies the transform function map for the template. The transform function map is used to apply transformations to fields in the merged data structure. They are simple strings with no parameters and the key to the

type JSONMarshaler

type JSONMarshaler interface {
	Marshal(obj interface{}) ([]byte, error)
}

func DefaultMarshaler

func DefaultMarshaler() JSONMarshaler

type Template

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

Template is the main templating engine

func (*Template) Execute

func (t *Template) Execute(writer io.Writer, params interface{}) error

Execute writes the expanded template to the supplied io.Writer

func (*Template) Validate

func (t *Template) Validate() (bool, []string)

Validate validates the template tags

type TransformFunc

type TransformFunc func(interface{}) []byte

TransformFunc is the transformation function for template expressions

func DefaultJSONTransformFunc

func DefaultJSONTransformFunc(marshaler JSONMarshaler) TransformFunc

DefaultJSONTransformFunc is the default JSON transform function

type TransformFunctionMap

type TransformFunctionMap map[string]TransformFunc

TransformFunctionMap is the function transform map for the templates.

Jump to

Keyboard shortcuts

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