codegen

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package codegen is a small package intended to help with integrating custom code generation tools in your project. It provides a 5 steps standardized workflow as follows:

  • Load a package, parse its source code, produce an AST.
  • Scan the loaded package and AST to produce an information tree (custom step).
  • Load a (custom) template file and apply it to the extracted information tree.
  • Format the generate output through go-imports.
  • Save the generated file to disk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTemplate

func ApplyTemplate(templateFn string, data interface{}) error

ApplyTemplate loads a template file, executes it on the `data` object, formats the output through go-imports, and save the result alongside the original template file with a .go extension.

func LoadPackage

func LoadPackage(name string) (pkg *packages.Package, err error)

LoadPackage loads and parses the source code of a package names relative to the current working directory

Types

type Field

type Field struct {
	Names []string
	Type  string
}

Field captures one fragment of the textual representation of a function argument list, return list or receiver list

type Fields

type Fields []Field

Fields captures all fragments of the textual representation of a function argument list, return list or receiver list

func FieldsFromAST

func FieldsFromAST(fset *token.FileSet, l *ast.FieldList) (fields Fields)

FieldsFromAST capture the textual components of an ast.FieldList and returns the corresponding codegen.Fields.

func (Fields) Fwd

func (ff Fields) Fwd() string

Fwd returns a string representation of a forwarding list for the fields, assuming all fields have a name

func (Fields) String

func (ff Fields) String() string

String returns a string representation of the fields

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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