package codegen
import "github.com/gohugoio/hugo/codegen"
Package codegen contains helpers for code generation.
Index ¶
- type Inspector
- func NewInspector(root string) *Inspector
- func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.Type) Methods
- type Method
- func (m Method) Declaration(receiver string) string
- func (m Method) DeclarationNamed(receiver string) string
- func (m Method) Delegate(receiver, delegate string) string
- func (m Method) String() string
- type Methods
Types ¶
type Inspector ¶
type Inspector struct {
ProjectRootDir string
// contains filtered or unexported fields
}
Inspector provides methods to help code generation. It uses a combination of reflection and source code AST to do the heavy lifting.
func NewInspector ¶
NewInspector creates a new Inspector given a source root.
func (*Inspector) MethodsFromTypes ¶
MethodsFromTypes create a method set from the include slice, excluding any method in exclude.
type Method ¶
type Method struct {
// The interface we extracted this method from.
Owner reflect.Type
// String version of the above, on the form PACKAGE.NAME, e.g.
// page.Page
OwnerName string
// Method name.
Name string
// Imports needed to satisfy the method signature.
Imports []string
// Argument types, including any package prefix, e.g. string, int, interface{},
// net.Url
In []string
// Return types.
Out []string
}
Method holds enough information about it to recreate it.
func (Method) Declaration ¶
Declaration creates a method declaration (without any body) for the given receiver.
func (Method) DeclarationNamed ¶
DeclarationNamed creates a method declaration (without any body) for the given receiver with named return values.
func (Method) Delegate ¶
Delegate creates a delegate call string.
func (Method) String ¶
type Methods ¶
type Methods []Method
Methods represents a list of methods for one or more interfaces. The order matches the defined order in their source file(s).
func (Methods) Imports ¶
Imports returns a sorted list of package imports needed to satisfy the signatures of all methods.
func (Methods) ToMarshalJSON ¶
ToMarshalJSON creates a MarshalJSON method for these methods. Any method name matching any of the regexps in excludes will be ignored.
Source Files ¶
- Version
- v0.153.4 (latest)
- Published
- Dec 28, 2025
- Platform
- linux/amd64
- Imports
- 13 packages
- Last checked
- 4 months ago –
Tools for package owners.