codegen

package module
v0.0.0-...-31dbb72 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0, BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Template

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

Template is a wrapper around the text/template package that provides a generic way for generating files according to the "go generate" pattern.

In addition to the standard template delimiters (https://pkg.go.dev/text/template), it supports /*{{ ... }}*/, which allows to "hide" template code in go comments. Data is provided to the template as function pipelines.

func NewTemplate

func NewTemplate(mappings template.FuncMap) *Template

NewTemplate creates a new Template with the given pipeline mappings.

func (*Template) Generate

func (t *Template) Generate(fileName string, optGenerator ...func() (string, error)) error

Generate generates the file with the given fileName (it can receive an optional generator function that overrides the way the content is generated).

func (*Template) GenerateContent

func (t *Template) GenerateContent() (string, error)

GenerateContent generates the dynamic content of the file by processing the template.

func (*Template) Parse

func (t *Template) Parse(fileName string) error

Parse parses the given file and extracts the header and content by splitting the file at the "go:generate" directive. It automatically removes existing "//go:build ignore" directives from the header.

Directories

Path Synopsis
features
cmd
Package gen/cmd allows to generate .go source files using the go:generate command.
Package gen/cmd allows to generate .go source files using the go:generate command.
cmd
example
Code generated by go generate; DO NOT EDIT.
Code generated by go generate; DO NOT EDIT.

Jump to

Keyboard shortcuts

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