Documentation ¶
Overview ¶
Package interpol provides utility functions for doing format-string like string interpolation using named parameters. Currently, a template only accepts variable placeholders delimited by brace characters (eg. "Hello {foo} {bar}").
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnexpectedClose = errors.New("interpol: unexpected close in template") ErrExpectingClose = errors.New("interpol: expecting close in template") ErrKeyNotFound = errors.New("interpol: key not found") ErrReadByteFailed = errors.New("interpol: read byte failed") )
Errors returned when formatting templates.
Functions ¶
Types ¶
type Func ¶
Func receives the placeholder key and writes to the io.Writer. If an error happens, the function can return an error, in which case the interpolation will be aborted.
type Interpolator ¶ added in v1.1.0
type Interpolator struct {
// contains filtered or unexported fields
}
Interpolator interpolates Template to Output, according to Format.
func New ¶ added in v1.1.0
func New(opts ...Option) *Interpolator
New creates a new interpolator with the given list of options. You can use options such as the ones returned by WithTemplate, WithFormat and WithOutput.
func NewWithOptions ¶ added in v1.1.0
func NewWithOptions(opts *Options) *Interpolator
NewWithOptions creates a new interpolator with the given options.
func (*Interpolator) Interpolate ¶ added in v1.1.0
func (i *Interpolator) Interpolate() error
Interpolate reads runes from Template and writes them to Output, with the exception of placeholders which are passed to Format.
type Option ¶ added in v1.1.0
type Option func(OptionSetter)
Option is an option that can be applied to an Interpolator.
func WithFormat ¶ added in v1.1.0
WithFormat assigns Format to Options.
func WithOutput ¶ added in v1.1.0
WithOutput assigns Output to Options.
func WithTemplate ¶ added in v1.1.0
WithTemplate assigns Template to Options.