Documentation
¶
Overview ¶
Package transform converts the protobuf semantic model into a Go-oriented intermediate representation suitable for code rendering.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateCreateOptions ¶
ValidateCreateOptions checks that each required_field listed in a create_message annotation refers to an existing field that is optional in the source message. A non-optional field is already required, so listing it in required_fields is an error. Call this after parsing, before rendering.
Types ¶
type GoEnum ¶
type GoEnum struct {
// GoName is the Go type name (e.g. "Person_Status" for nested enums).
GoName string
// Comment lines from the proto source.
Comment model.Comment
// Values are the enum constants.
Values []GoEnumValue
}
GoEnum is a flattened enum with resolved Go names.
type GoEnumValue ¶
type GoEnumValue struct {
// GoName is the Go constant name (e.g. "Person_Status_STATUS_ACTIVE").
GoName string
// Number is the proto enum value number.
Number int32
// Comment lines from the proto source.
Comment model.Comment
}
GoEnumValue is a single enum constant.
type GoField ¶
type GoField struct {
model.Field
// GoName is the Go struct field name after CamelCase and conflict resolution.
GoName string
// GoType is the fully resolved Go type string (e.g. "int32", "[]byte", "*Person").
GoType string
// GormMessageOptions is copied from the owning message's GormOptions.
// Nil means the message has no GORM annotation and no gorm tag should be generated.
GormMessageOptions *model.GormMessageOptions
}
GoField is a message field with resolved Go naming and type info. It embeds model.Field to preserve proto-level metadata (field number, type kind, scalar kind, cardinality) needed by marshal/unmarshal generation. GormMessageOptions carries the owning message's GORM annotation so that tag providers can make per-field decisions without needing the parent GoMessage.
type GoFile ¶
type GoFile struct {
// Source is the original proto file path (used in the generated header).
Source string
// Package is the Go package name for the generated file.
Package string
// ProtoPackage is the proto package name (e.g., "compat"). Used by the
// TS renderer to compute correct short type names for cross-file references.
ProtoPackage string
// Messages contains all messages (including nested) flattened to top level.
Messages []GoMessage
// Enums contains all enums (including nested) flattened to top level.
Enums []GoEnum
// Services contains all service definitions with resolved Go names.
Services []GoService
}
GoFile is the Go-oriented view of a single proto file, ready for rendering.
func Flatten ¶
Flatten converts a model.File into a GoFile by:
- Extracting the Go package name from go_package option.
- Recursively flattening nested messages and enums to top level.
- Resolving Go type names, field names, and enum value names via the naming package.
- Resolving field name conflicts within each message.
type GoMessage ¶
type GoMessage struct {
// GoName is the Go struct name (e.g. "Person_Address" for nested types).
GoName string
// Comment lines from the proto source.
Comment model.Comment
// Fields with resolved Go names and types.
Fields []GoField
// UpdateSource is non-empty when this message was generated from an update_message
// annotation. Its value is the source message name, used to generate ToMap() and
// inherit validate rules.
UpdateSource string
// CreateSource is non-empty when this message was generated from a create_message
// annotation. Its value is the source message name, used to inherit validate rules.
CreateSource string
// ConditionFields lists the condition_fields declared in the update_message annotation.
// These are WHERE-condition fields and must not appear in ToMap() output.
// Only populated when UpdateSource is non-empty.
ConditionFields []string
// GormMessageOptions carries the message-level GORM annotation.
// Used by render to generate TableName() and decide whether to emit gorm struct tags.
// Nil means no GORM annotation is present.
GormMessageOptions *model.GormMessageOptions
}
GoMessage is a flattened message with resolved Go names.
type GoRPCMethod ¶
type GoRPCMethod struct {
// GoName is the Go method name (e.g. "CreateUser").
GoName string
// RequestType is the Go type name of the request message (e.g. "CreateUserRequest").
RequestType string
// ResponseType is the Go type name of the response message (e.g. "CreateUserResponse").
ResponseType string
// Comment lines from the proto source.
Comment model.Comment
}
GoRPCMethod is a single rpc method with resolved Go type names.
type GoService ¶
type GoService struct {
// GoName is the Go interface name (e.g. "UserService").
GoName string
// Comment lines from the proto source.
Comment model.Comment
// Methods are the rpc methods of the service.
Methods []GoRPCMethod
}
GoService is a service definition with resolved Go names.
type TransformError ¶ added in v0.3.0
TransformError is the domain error type for transform-layer validation errors. Use errorx.NewSentinelf[transformTag] to create instances with runtime context.