package gengo
import "k8s.io/gengo/v2"
Package gengo is a code-generation framework.
Index ¶
- Constants
- func Execute(nameSystems namer.NameSystems, defaultSystem string, getTargets func(*generator.Context) []generator.Target, buildTag string, patterns []string) error
- func ExtractCommentTags(marker string, lines []string) map[string][]string
- func ExtractFunctionStyleCommentTags(marker string, tagNames []string, lines []string) (map[string][]Tag, error)
- func ExtractSingleBoolCommentTag(marker string, key string, defaultVal bool, lines []string) (bool, error)
- func GoBoilerplate(headerFile, buildTag, generatedBy string) ([]byte, error)
- type Tag
Constants ¶
const StdBuildTag = "ignore_autogenerated"
StdBuildTag is a suggested build-tag which tools can use both as an argument to GoBoilerplate and to Execute.
const StdGeneratedBy = "// Code generated by GENERATOR_NAME. DO NOT EDIT."
StdGeneratedBy is a suggested "generated by" line which tools can use as an argument to GoBoilerplate.
Functions ¶
func Execute ¶
func Execute(nameSystems namer.NameSystems, defaultSystem string, getTargets func(*generator.Context) []generator.Target, buildTag string, patterns []string) error
Execute implements most of a tool's main loop.
func ExtractCommentTags ¶
ExtractCommentTags parses comments for lines of the form:
'marker' + "key=value".
Values are optional; "" is the default. A tag can be specified more than one time and all values are returned. If the resulting map has an entry for a key, the value (a slice) is guaranteed to have at least 1 element.
Example: if you pass "+" for 'marker', and the following lines are in the comments:
+foo=value1 +bar +foo=value2 +baz="qux"
Then this function will return:
map[string][]string{"foo":{"value1, "value2"}, "bar": {""}, "baz": {`"qux"`}}
Deprecated: Prefer codetags.Extract and codetags.Parse.
func ExtractFunctionStyleCommentTags ¶
func ExtractFunctionStyleCommentTags(marker string, tagNames []string, lines []string) (map[string][]Tag, error)
ExtractFunctionStyleCommentTags parses comments for special metadata tags.
This function is a wrapper around codetags.Extract and codetags.Parse, but only supports tags with a single position arg of type string.
func ExtractSingleBoolCommentTag ¶
func ExtractSingleBoolCommentTag(marker string, key string, defaultVal bool, lines []string) (bool, error)
ExtractSingleBoolCommentTag parses comments for lines of the form:
'marker' + "key=value1"
If the tag is not found, the default value is returned. Values are asserted to be boolean ("true" or "false"), and any other value will cause an error to be returned. If the key has multiple values, the first one will be used.
This function is a wrapper around codetags.Extract and codetags.Parse, but only supports tags with a single position arg of type string, and a value of type bool.
func GoBoilerplate ¶
GoBoilerplate returns the Go file header: - an optional build tag (negative, set it to ignore generated code) - an optional boilerplate file - an optional "generated by" comment
Types ¶
type Tag ¶
type Tag struct { // Name is the name of the tag with no arguments. Name string // Args is a list of optional arguments to the tag. Args []string // Value is the value of the tag. Value string }
Tag represents a single comment tag.
func (Tag) String ¶
Source Files ¶
comments.go execute.go
Directories ¶
Path | Synopsis |
---|---|
codetags | |
examples | |
examples/kilroy | kilroy is a trivial gengo/v2 program which adds a tag-method to types. |
examples/pointuh | pointuh is a trivial gengo/v2 program which consider its inputs, and emits to new packages the same types, except for structs, where all fields are pointers. |
examples/tracer | tracer is a trivial gengo/v2 program which prints the various hooks as they are called. |
generator | Package generator defines an interface for code generators to implement. |
namer | Package namer has support for making different type naming systems. |
parser | Package parser provides code to parse go files, type-check them, extract the types. |
parser/tags | |
types | Package types contains go type information, packaged in a way that makes auto-generation convenient, whether by template or straight go functions. |
- Version
- v2.0.0-20250531010418-b22feca77200 (latest)
- Published
- May 31, 2025
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 6 days ago –
Tools for package owners.