Documentation
¶
Overview ¶
Package common holds structalign's public contracts: the interfaces that decouple the CLI's layers and the plain data types those interfaces traffic in. Implementations live under internal/. Keeping the contracts here (rather than internal/) lets mockery generate mocks from a non-internal source.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffStyleStrings ¶
func DiffStyleStrings() []string
DiffStyleStrings returns a slice of all String values of the enum
Types ¶
type Aligner ¶
Aligner produces the struct-reordering findings for one Target. patterns is a set of glob patterns matched against named-type names (nil = all). When keepTags is false, field tags are stripped from the rendered struct text.
type DiffStyle ¶
type DiffStyle uint8
DiffStyle selects how a Finding is rendered. enumer generates its String/parse/text-marshal helpers and a flag.Value implementation (Set), see diffstyle_enumer.go; the names map to "unified"/"side"/"none" via -trimprefix=Diff -transform=lower.
func DiffStyleString ¶
DiffStyleString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func DiffStyleValues ¶
func DiffStyleValues() []DiffStyle
DiffStyleValues returns all values of the enum
func (DiffStyle) IsADiffStyle ¶
IsADiffStyle returns "true" if the value is listed in the enum definition. "false" otherwise
func (DiffStyle) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for DiffStyle
func (*DiffStyle) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for DiffStyle
type Finding ¶
type Finding struct {
Fset *token.FileSet
Pos token.Pos
Name string // enclosing named type, or "" for an anonymous struct
Message string // analyzer diagnostic (carries the size info)
Original string // current struct source ("struct{...}")
Proposed string // reordered struct from the analyzer's SuggestedFix
}
Finding is one struct whose fields could be reordered to use less memory.
type Inspector ¶
Inspector computes the memory layout of each named struct in a Target, filtered by the same glob patterns as Aligner (nil = all).
type Layout ¶
type Layout struct {
Name string
Total int64
Align int64
Padding int64 // total padding across all fields
Fields []LayoutField
}
Layout is one named struct's computed memory layout.
type LayoutField ¶
type LayoutField struct {
Name string
Type string
Tag string // raw struct tag without backticks, or ""
Offset int64
Size int64
Align int64
Padding int64 // padding inserted after this field
}
LayoutField is one field's place in a struct's memory layout.
type Loader ¶
Loader resolves Go package patterns (./..., import paths, directories, and "file=" queries) into typed Targets.
type Sizes ¶
type Sizes interface {
Sizeof(t types.Type) int64
Alignof(t types.Type) int64
Offsetsof(fields []*types.Var) []int64
}
Sizes abstracts go/types sizing so the target architecture is injectable: a real types.Sizes in production, a fixed types.SizesFor("gc","amd64") in tests (making golden output deterministic on any host arch). Its method set matches go/types.Sizes, so a common.Sizes value is directly assignable to a types.Sizes (e.g. analysis.Pass.TypesSizes).
type Target ¶
type Target struct {
PkgPath string
Fset *token.FileSet
Syntax []*ast.File
Types *types.Package
TypesInfo *types.Info
Sizes Sizes
Errors []error
}
Target is a loader-agnostic view of one typed Go package: everything the analyzer and the layout inspector need, without exposing go/packages.Package.