handlers

package
v0.0.0-...-d3fa72d Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CollectionTemplater

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

func NewCollectionTemplater

func NewCollectionTemplater(outputPath string, template *template.Template, formatGoCode bool) *CollectionTemplater

NewCollectionTemplater creates a TagHandler that will collect the names and tags of all tagged declarations and pass them to a Go template as a collection. The outputPath parameter determines the path of the output file.

func (*CollectionTemplater) BeginFile

func (ct *CollectionTemplater) BeginFile(context tagproc.TagContext) error

func (*CollectionTemplater) Delay

func (ct *CollectionTemplater) Delay()

func (*CollectionTemplater) Finalize

func (ct *CollectionTemplater) Finalize() error

func (*CollectionTemplater) FinishFile

func (ct *CollectionTemplater) FinishFile(context tagproc.TagContext) error

func (*CollectionTemplater) HandleTag

func (ct *CollectionTemplater) HandleTag(context tagproc.TagContext, obj *ast.Object, tagLiteral string) error

func (*CollectionTemplater) SetTemplateMapper

func (tc *CollectionTemplater) SetTemplateMapper(mapper func(*templateEntry))

SetTemplateMapper allows you to specify a function that will be applied to the map containing the data that will be passed to the template engine. Use this to provide custom data. It can be accessed in the template via `Data.yourname`

func (*CollectionTemplater) WriteTemplate

func (ct *CollectionTemplater) WriteTemplate() error

type FieldAdder

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

func NewFieldAdder

func NewFieldAdder(name, typ, importPath, tag string) *FieldAdder

NewFieldAdder creates a new tag handler that adds a field to whatever struct the target tag appears on. The name, typ, and importPath parameters are used to give the name and type of the field and the import path for the type. The tag parameter sets the field's tag. This handler will also add imports to the target type if necessary. Set the import path to the empty string to prevent this.

func (*FieldAdder) BeginFile

func (_ *FieldAdder) BeginFile(context tagproc.TagContext) error

func (*FieldAdder) Finalize

func (_ *FieldAdder) Finalize() error

func (*FieldAdder) FinishFile

func (_ *FieldAdder) FinishFile(context tagproc.TagContext) error

func (*FieldAdder) HandleTag

func (fa *FieldAdder) HandleTag(context tagproc.TagContext, obj *ast.Object, tagLiteral string) error

type InceptionTemplater

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

func NewInceptionTemplater

func NewInceptionTemplater(outputPath string, template *template.Template, parameters ...string) *InceptionTemplater

NewInceptionTemplater creates a handler that applies the inception principle: c.f. https://journal.paul.querna.org/articles/2014/03/31/ffjson-faster-json-in-go/ This means: It will apply the template to all collected tags like the collection templater handler. When it has done that, it will proceed by running the generated file as a Go file, allowing you to use reflection on types from your own package.

func (*InceptionTemplater) BeginFile

func (ct *InceptionTemplater) BeginFile(context tagproc.TagContext) error

func (*InceptionTemplater) Delay

func (ct *InceptionTemplater) Delay()

Delay prevents any generation of files in the Finalize function and instead requires you to call PerformInception at another time that is more suitable for your uses. This might be required when using an inception-based approach.

func (*InceptionTemplater) Finalize

func (ct *InceptionTemplater) Finalize() error

func (*InceptionTemplater) FinishFile

func (ct *InceptionTemplater) FinishFile(context tagproc.TagContext) error

func (*InceptionTemplater) HandleTag

func (ct *InceptionTemplater) HandleTag(context tagproc.TagContext, obj *ast.Object, tagLiteral string) error

func (*InceptionTemplater) PerformInception

func (ct *InceptionTemplater) PerformInception() error

func (*InceptionTemplater) SetTemplateMapper

func (tc *InceptionTemplater) SetTemplateMapper(mapper func(*templateEntry))

SetTemplateMapper allows you to specify a function that will be applied to the map containing the data that will be passed to the template engine. Use this to provide custom data. It can be accessed in the template via `Data.yourname`

type Templater

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

func NewTemplater

func NewTemplater(outputPath string, template *template.Template, makeName func(string) string, formatGoCode bool) *Templater

NewTemplater returns a TagHandler that instantiates a Go-template for each tagged struct or interface with the declared name and its tags as the template's argument. The parameters outputPath and makeName control the path to write the instantiated templates to and how the declared name of a struct or interface corresponds to the file name. The template parameter specifies the template that should be instantiated.

func (*Templater) BeginFile

func (_ *Templater) BeginFile(context tagproc.TagContext) error

func (*Templater) Delay

func (t *Templater) Delay()

Delay prevents any generation of files in the Finalize function and instead requires you to call WriteTemplates at another time that is more suitable for your uses. This might be required when using an inception-based approach.

func (*Templater) Finalize

func (t *Templater) Finalize() error

func (*Templater) FinishFile

func (_ *Templater) FinishFile(context tagproc.TagContext) error

func (*Templater) HandleTag

func (t *Templater) HandleTag(context tagproc.TagContext, obj *ast.Object, tagLiteral string) error

func (*Templater) SetTemplateMapper

func (tc *Templater) SetTemplateMapper(mapper func(*templateEntry))

SetTemplateMapper allows you to specify a function that will be applied to the map containing the data that will be passed to the template engine. Use this to provide custom data. It can be accessed in the template via `Data.yourname`

func (*Templater) WriteTemplates

func (t *Templater) WriteTemplates() error

Jump to

Keyboard shortcuts

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