Documentation
¶
Overview ¶
Package gengo provides utilities for building code generators in Go
Index ¶
- Constants
- func Filepath(pkg *packages.Package, filename string) string
- func Format(filename string, src []byte, opt *imports.Options) ([]byte, error)
- func Inspect(pkg *packages.Package, f func(n ast.Node) (bool, error)) error
- func Load(cfg *packages.Config, patterns ...string) ([]*packages.Package, error)
- func PrintHeader(w io.Writer, pkg string, imports ...string)
- func Write(filename string, src []byte, opt *imports.Options) error
Constants ¶
const ( // Version is the version of this package being used Version = "v0.3.15" // GitCommit is the commit just before the latest version commit GitCommit = "ec77a15" // VersionDate is the date-time of the latest version commit in UTC (in the format 'YYYY-MM-DD HH:MM', which is the Go format '2006-01-02 15:04') VersionDate = "2023-12-21 00:27" )
Variables ¶
This section is empty.
Functions ¶
func Filepath ¶ added in v0.3.1
Filepath returns the filepath of a file in the given package with the given filename relative to the package.
func Format ¶
Format returns the given bytes with goimports applied. It wraps imports.Process by wrapping any error with additional context.
func Inspect ¶
Inspect goes through all of the files in the given package and calls the given function on each node in files that are not generated. The bool return value from the given function indicates whether to continue traversing down the AST tree of that node and look at its children. If a non-nil error value is returned by the given function, the traversal of the tree is stopped and the error value is returned.
func Load ¶
Load loads and returns the Go packages named by the given patterns. Load calls packages.Load and ensures that there is at least one package; this means that, if there is a nil error, the length of the resulting packages is guaranteed to be greater than zero.
func PrintHeader ¶
PrintHeader prints a header to the given writer for a generated file in the given package with the given imports. Imports do not need to be set if you are running Format on the code later, but they should be set for any external packages that many not be found correctly by goimports.
Types ¶
This section is empty.