Documentation
¶
Overview ¶
Package transform provides a small, composable layer to apply structural rewrites to syntetic/model graphs without polluting the core model or the builders. It defines a Transformer interface and helpers to compose and apply transformations to packages, types, and nodes.
Index ¶
- func ApplyNode(n mdl.Node, ts ...Transformer) mdl.Node
- func ApplyPackage(p *mdl.Package, ts ...Transformer) *mdl.Package
- func ApplyType(t *mdl.Type, ts ...Transformer) *mdl.Type
- func LookupDeclName(tr Transformer, t *mdl.Type) (string, bool)
- type DeclNameProvider
- type Nop
- type TagOption
- type TagTransformer
- type Transformer
- func Compose(ts ...Transformer) Transformer
- func DeclNameOverride(fn func(*mdl.Type) (string, bool)) Transformer
- func FieldRewriter(fn func(mdl.Field) (mdl.Field, bool)) Transformer
- func FromTags(opts ...TagOption) Transformer
- func NodeRewriter(fn func(mdl.Node) mdl.Node) Transformer
- func TypeRewriter(fn func(*mdl.Type) *mdl.Type) Transformer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyNode ¶
func ApplyNode(n mdl.Node, ts ...Transformer) mdl.Node
ApplyNode applies transformers to a node.
func ApplyPackage ¶
func ApplyPackage(p *mdl.Package, ts ...Transformer) *mdl.Package
ApplyPackage applies transformers to a package.
func ApplyType ¶
func ApplyType(t *mdl.Type, ts ...Transformer) *mdl.Type
ApplyType applies transformers to a type.
func LookupDeclName ¶
func LookupDeclName(tr Transformer, t *mdl.Type) (string, bool)
LookupDeclName attempts to retrieve a decl-name override from a transformer, returning (name, true) when available.
Types ¶
type DeclNameProvider ¶
DeclNameProvider exposes a declaration-name override for model.Type values. Builders can use this to override the printed name without mutating the type.
type TagOption ¶
type TagOption func(*TagTransformer)
TagOption configures the TagTransformer.
func WithFlatKey ¶
WithFlatKey sets the directive name for embedding/flattening (default: "flat").
func WithInlineKey ¶
WithInlineKey sets an additional directive alias for embedding/flattening (default: "inline").
func WithOmitKey ¶
WithOmitKey sets the directive name for omitting a field (default: "omit").
func WithRenameKey ¶
WithRenameKey sets the directive name for field rename (default: "rename").
func WithTagKey ¶
WithTagKey sets the struct tag key to read directives from (default: "x").
func WithTagOverrideKey ¶
WithTagOverrideKey sets the directive name used to override the field tag (default: "tag").
func WithTypeKey ¶
WithTypeKey sets the directive name for type override (default: "type").
type TagTransformer ¶
type TagTransformer struct {
// contains filtered or unexported fields
}
TagTransformer applies struct-field level rewrites based on a configurable tag namespace (default key: x). Supported directives:
- type: fully-qualified type path "pkg/import/path.Name" to override field type
- rename: new field name for emission
- omit: drop this field from emission
- flat / inline: mark field as embedded (flatten)
- tag: override field tag for emission (raw literal without backticks)
The transformer operates on model.Nodes. For *model.Struct it evaluates and applies directives to each field; it recurses into nested nodes.
func (*TagTransformer) ApplyPackage ¶
func (t *TagTransformer) ApplyPackage(p *mdl.Package) *mdl.Package
type Transformer ¶
type Transformer interface {
// ApplyPackage applies this transform to a package. Implementations may
// walk files, types, and fields as needed.
ApplyPackage(p *mdl.Package) *mdl.Package
// ApplyType applies this transform to a single type.
ApplyType(t *mdl.Type) *mdl.Type
// ApplyNode applies this transform to a node.
ApplyNode(n mdl.Node) mdl.Node
}
Transformer applies structural rewrites to model graphs. Implementations may operate in-place or return new values. Callers should not rely on mutation semantics; always use the returned value.
func Compose ¶
func Compose(ts ...Transformer) Transformer
Compose builds a transformer that applies the provided transformers in order. Nil transformers are ignored. When no transformers are supplied, a no-op transformer is returned.
func DeclNameOverride ¶
func DeclNameOverride(fn func(*mdl.Type) (string, bool)) Transformer
DeclNameOverride returns a Transformer that provides a declaration-name override for types using the supplied function.
func FieldRewriter ¶
FieldRewriter returns a Transformer that applies fn to all fields within struct nodes, allowing field modification or removal (return ok=false to drop).
func FromTags ¶
func FromTags(opts ...TagOption) Transformer
FromTags returns a transformer that applies tag-driven rewrites.
func NodeRewriter ¶
func NodeRewriter(fn func(mdl.Node) mdl.Node) Transformer
NodeRewriter returns a Transformer that applies fn to every node, recursing into child nodes where applicable.
func TypeRewriter ¶
func TypeRewriter(fn func(*mdl.Type) *mdl.Type) Transformer
TypeRewriter returns a Transformer that applies fn to types.