Documentation
¶
Overview ¶
Package render generates Go source code from the Go-oriented intermediate representation produced by the transform package. It outputs formatted Go source bytes suitable for writing to .pb.dao.go files.
Index ¶
- Variables
- func File(gf transform.GoFile, modulePath string, ctx Context) ([]byte, error)
- func HTTPFile(gf transform.GoFile, modulePath string) ([]byte, error)
- func RPCFile(gf transform.GoFile) ([]byte, error)
- func ValidateFile(gf transform.GoFile, modulePath string, ctx Context) ([]byte, error)
- type Context
- type GormTagProvider
- type RenderError
- type TagProvider
Constants ¶
This section is empty.
Variables ¶
var ErrTooManyFields = errorx.NewSentinel[renderTag]("render: message has more than 128 non-repeated fields")
ErrTooManyFields is returned when a message has more than 128 non-repeated fields, which exceeds the bitmask capacity used for duplicate detection.
Functions ¶
func File ¶
File renders a complete Go source file from a GoFile. The returned bytes are gofmt-formatted and ready to write to disk.
func HTTPFile ¶
HTTPFile renders a Go source file containing gin HTTP handler factory functions for all services in gf. Each rpc method gets a XxxHandler(svc XxxService) gin.HandlerFunc function. The returned bytes are gofmt-formatted and ready to write to a .pb.http.go file. Callers should only invoke this when len(gf.Services) > 0.
func RPCFile ¶
RPCFile renders a Go source file containing interface definitions for all services in gf. The returned bytes are gofmt-formatted and ready to write to a .pb.rpc.go file. Callers should only invoke this when len(gf.Services) > 0.
func ValidateFile ¶
ValidateFile renders a complete .pb.dao.validate.go source file from a GoFile. Every message gets a Validate() error method; messages without constraints get an empty method that returns nil, ensuring interface consistency. For update/create messages (UpdateSource/CreateSource non-empty), validate rules are read directly from the derived message's own fields (which carry validate annotations from gen-proto). The returned bytes are gofmt-formatted and ready to write to disk.
Types ¶
type Context ¶
type Context struct {
// MessageIndex maps GoName to GoMessage for cross-file lookups.
// Used by ToEntity, ApplyTo, and GormMessageOptions propagation to find the source message.
// Not used by ValidateFile: validate rules are read directly from derived message fields.
MessageIndex map[string]*transform.GoMessage
// EnumIndex maps GoName to GoEnum for cross-file enum lookups.
// Used by ValidateFile to resolve enum defined_only checks when
// the enum is defined in a different file from the derived message.
EnumIndex map[string]transform.GoEnum
}
Context carries cross-file context needed during rendering. A zero-value Context is valid and disables context-dependent features (ToMap generation, ToEntity/ApplyTo generation, GormMessageOptions propagation).
type GormTagProvider ¶
type GormTagProvider struct{}
GormTagProvider generates gorm struct tags for fields belonging to messages that have a GORM annotation (GormMessageOptions != nil).
func (*GormTagProvider) Key ¶
func (p *GormTagProvider) Key() string
Key returns the struct tag key "gorm".
func (*GormTagProvider) Value ¶
func (p *GormTagProvider) Value(f transform.GoField) string
Value returns the gorm tag value for the field, or empty string if the owning message has no GORM annotation. The column name defaults to the proto field name; it can be overridden via the field-level GormFieldOptions.Column annotation.
type RenderError ¶ added in v0.3.0
RenderError is the sentinel error type for render-package errors. Use errors.As(err, new(render.RenderError)) to match any render-package error.