generate

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(gen CodeGenerator, inputs []Input)

Generate populates the provided input, executes the template provided by the CodeGenerator, and writes the template's output to the filename provided by the CodeGenerator.

Types

type CodeGenerator

type CodeGenerator interface {
	// Name returns a unique identifier for an instance of
	// generation. Name contributes to part of the generated
	// filename. Each invocation of `//go:generate` within a
	// file must return a different result from Name. Name
	// may return the empty string.
	Name() string

	// Template returns the template used to generate the
	// output file. A Go `package` expression for the package
	// of the file invoking `//go:generate` will automatically
	// be prepended to the template's output along with a
	// comment identifying the file as generated.
	Template() *template.Template

	// Data returns the value passed as the `data` param into
	// the template.Template.Execute() method.
	Data() interface{}
}

type Input

type Input struct {
	Type InputType

	// The where to store the input's value.
	Dst *string

	// Either the name of the flag or the name
	// of the environment variable.
	Key string
}

Input defines a CLI flag or environment variable used as input to a code generator. An Input is usually used to populate a field of a struct implementing the CodeGenerator interface.

type InputType

type InputType int
const (
	Flag InputType = iota
	EnvVar
)

Jump to

Keyboard shortcuts

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