Documentation
¶
Overview ¶
Command wrapgen generates wrapper methods for embedded struct fields tagged with `gen:"wrap"`. It uses go/types (through golang.org/x/tools/go/packages) and proxies any method signature (params, variadics, and multiple return values). It skips methods that have a leading comment line containing [excludeTag].
How it decides which package to process:
- By default it processes the package in the current directory (flag -dir).
- The generator automatically processes any package that contains structs with embedded fields tagged with `gen:"wrap"`.
How it decides what to wrap:
- It scans *struct types* in the package.
- For each embedded field whose struct tag contains `gen:"wrap"`, it finds methods of the embedded type (pointer or value receiver) defined in the *same package* and generates wrappers on the outer struct that:
- Lazily initialize the embedded field if it's a pointer and nil.
- Forward all parameters and return a pointer to the outer struct (fluent interface).
- If the original method's leading comment includes [excludeTag], that method is skipped.
- If the outer struct already defines a method with the same name, the wrapper is not generated (no clobbering).
Example usage in your code:
type ValueReferenceHolder struct { /* ... */ }
// Some is eligible for wrapping (unless you add [excludeTag] above).
func (r *ValueReferenceHolder) Some() { /* ... */ }
type IgnorePointerAttributes struct {
*ValueReferenceHolder `gen:"wrap"` // <- tag tells wrapgen to proxy methods
*ThemeConsumer // <- not tagged, ignored
Ignoring duit_utils.Tristate[bool] `json:"ignoring,omitempty"`
}
// Generated wrapper will return *IgnorePointerAttributes for fluent interface:
attrs := NewIgnorePointerAttributes().
Some(). // returns *IgnorePointerAttributes
Some2() // returns *IgnorePointerAttributes
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmbeddedStructDelegateGenerator ¶
func EmbeddedStructDelegateGenerator()
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.