Documentation
¶
Overview ¶
Package structinspect provides AST helpers for inspecting Go struct types and method receivers.
Index ¶
- func EmbeddedFieldPosMap(st *ast.StructType) map[string]token.Pos
- func EmbeddedTypeNames(st *ast.StructType) []string
- func HasDisallowedNamedFields(st *ast.StructType) bool
- func HasRequiredAppField(st *ast.StructType, info *types.Info) bool
- func ReceiverTypeName(expr ast.Expr) string
- type SubjectField
- type SubjectFieldResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmbeddedFieldPosMap ¶
func EmbeddedFieldPosMap( st *ast.StructType, ) map[string]token.Pos
EmbeddedFieldPosMap returns a map from embedded type name to the position of the embedding field identifier.
func EmbeddedTypeNames ¶
func EmbeddedTypeNames(st *ast.StructType) []string
EmbeddedTypeNames returns the names of all embedded types in a struct.
func HasDisallowedNamedFields ¶
func HasDisallowedNamedFields(st *ast.StructType) bool
HasDisallowedNamedFields reports whether a page struct contains any named field besides the single allowed `App *App`. Embedded fields are ignored (validated separately).
func HasRequiredAppField ¶
func HasRequiredAppField( st *ast.StructType, info *types.Info, ) bool
HasRequiredAppField reports whether the struct has the required `App *App` field.
func ReceiverTypeName ¶
ReceiverTypeName extracts the type name from a method receiver expression, handling both T and *T forms.
Types ¶
type SubjectField ¶
type SubjectField struct {
FieldName string // e.g. "SubjectUser"
Name string // e.g. "User"
SignalName string // e.g. "instance_id" (from signal:"instance_id" tag, empty otherwise)
Singular bool // true when the field type is string (not []string)
Pos token.Pos // position of the field name identifier
}
SubjectField describes a Subject-prefixed field found in a struct.
type SubjectFieldResult ¶
type SubjectFieldResult struct {
// Fields are the valid Subject fields found, in definition order.
Fields []SubjectField
// AfterPayload is non-nil when a Subject field appears after a
// non-Subject (payload) field. It points to the offending field.
AfterPayload *SubjectField
// DuplicateSignal is non-nil when two subject fields share the
// same signal:"..." tag value. It points to the second occurrence.
// DuplicateSignalFirst names the first field that used the signal.
DuplicateSignal *SubjectField
DuplicateSignalFirst string
// UserWithSignal is non-nil when SubjectUser has a signal:"..." tag.
// SubjectUser is auth-scoped and must not be bound to a signal.
UserWithSignal *SubjectField
// InvalidSignal is non-nil when a signal:"..." tag value is malformed.
InvalidSignal *SubjectField
}
SubjectFieldResult holds the result of inspecting a struct for Subject fields.
func SubjectFields ¶
func SubjectFields( ts *ast.TypeSpec, info *types.Info, ) SubjectFieldResult
SubjectFields inspects a type spec for Subject-prefixed fields. A valid Subject field has type string or []string. Returns the list of subject fields and whether any appear after payload fields.