gengo

package module
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: BSD-3-Clause Imports: 8 Imported by: 3

README

gengo

Go Reference Go Report Card

Gengo provides utilities for building code generators in Go. The standard path for a code generator is: Load -> PrintHeader -> Inspect -> Write.

Documentation

Overview

Package gengo provides utilities for building code generators in Go

Index

Constants

View Source
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

func Filepath(pkg *packages.Package, filename string) string

Filepath returns the filepath of a file in the given package with the given filename relative to the package.

func Format

func Format(filename string, src []byte, opt *imports.Options) ([]byte, error)

Format returns the given bytes with goimports applied. It wraps imports.Process by wrapping any error with additional context.

func Inspect

func Inspect(pkg *packages.Package, f func(n ast.Node) (bool, error)) error

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

func Load(cfg *packages.Config, patterns ...string) ([]*packages.Package, error)

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

func PrintHeader(w io.Writer, pkg string, imports ...string)

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.

func Write

func Write(filename string, src []byte, opt *imports.Options) error

Write writes the given bytes to the given filename after applying goimports using the given options.

Types

This section is empty.

Jump to

Keyboard shortcuts

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