render

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func File(gf transform.GoFile, modulePath string, ctx Context) ([]byte, error)

File renders a complete Go source file from a GoFile. The returned bytes are gofmt-formatted and ready to write to disk.

func HTTPFile

func HTTPFile(gf transform.GoFile, modulePath string) ([]byte, error)

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

func RPCFile(gf transform.GoFile) ([]byte, error)

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

func ValidateFile(gf transform.GoFile, modulePath string, ctx Context) ([]byte, error)

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

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

type RenderError = errorx.Sentinel[renderTag]

RenderError is the sentinel error type for render-package errors. Use errors.As(err, new(render.RenderError)) to match any render-package error.

type TagProvider

type TagProvider interface {
	Key() string
	Value(f transform.GoField) string
}

TagProvider generates a struct tag value for a single field. Return empty string to skip this tag for the field.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL