servergen

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package servergen generates zero-reflection transport codecs (request binding, validation, and response serialization) for typed server routes by analysing server.Register calls with go/packages. The codecs are an optimization: routes bind and serialize via a reflection fallback without them, so running `tyche generate` is never required — it just removes reflection from the hot path. Types declared in package main are keyed to match Go's runtime reflection, so single-file main.go apps work too.

Index

Constants

View Source
const GeneratedFilename = "zz_server_routes_gen.go"

Variables

This section is empty.

Functions

func CleanupGeneratedFiles

func CleanupGeneratedFiles(rootDir string, patterns []string, keep map[string]struct{}) error

func FindPackageDir

func FindPackageDir(routes []RouteSpec, pkgPath string) (string, bool)

func GeneratePackageManifest

func GeneratePackageManifest(pkgPath string, routes []RouteSpec) ([]byte, error)

func GroupRoutesByPackage

func GroupRoutesByPackage(routes []RouteSpec) map[string][]RouteSpec

func WriteGeneratedFiles

func WriteGeneratedFiles(dir string, patterns []string) error

Types

type BindFieldSpec

type BindFieldSpec struct {
	FieldName    string
	ParamName    string
	Source       string
	TypeExpr     string
	Kind         string
	ElemTypeExpr string
	ElemKind     string
	Rules        validation.FieldRules
	ElemPointer  bool
	Pointer      bool
	Required     bool
	Slice        bool
}

type BodyBindSpec

type BodyBindSpec struct {
	Direct       *BodyFieldSpec
	Target       string
	DecodeTarget string
	Fields       []BodyFieldSpec
	Required     bool
}

type BodyFieldSpec

type BodyFieldSpec struct {
	ElemNested    *BodyBindSpec
	Nested        *BodyBindSpec
	NestedType    string
	JSONName      string
	TypeExpr      string
	Kind          string
	ElemStruct    string
	ElemKind      string
	ElemType      string
	FieldName     string
	Rules         validation.FieldRules
	NestedPtr     bool
	Required      bool
	Opaque        bool
	ElemPtr       bool
	Slice         bool
	Pointer       bool
	ElemStructPtr bool
}

type BodyRequiredFieldSpec

type BodyRequiredFieldSpec struct {
	Pointer []string
	Path    []string
}

func RequiredJSONFieldsForBodySpec

func RequiredJSONFieldsForBodySpec(body *BodyBindSpec) []BodyRequiredFieldSpec

type HeaderFieldSpec

type HeaderFieldSpec struct {
	FieldName string
	Header    string
	TypeExpr  string
	Kind      string
	Pointer   bool
	Required  bool
}

type InputBindSpec

type InputBindSpec struct {
	Body   *BodyBindSpec
	Fields []BindFieldSpec
	Manual bool
}

type OutputBodyFieldSpec

type OutputBodyFieldSpec struct {
	FieldName string
	JSONName  string
	TypeExpr  string
	Kind      string
	Pointer   bool
}

type OutputBodySpec

type OutputBodySpec struct {
	TargetExpr      string
	Fields          []OutputBodyFieldSpec
	HasSimpleStatus bool
}

type OutputWriteSpec

type OutputWriteSpec struct {
	Body          *OutputBodySpec
	BodyFieldName string
	BodyTypeExpr  string
	StatusField   string
	Headers       []HeaderFieldSpec
	StaticStatus  int
	Manual        bool
}

type RouteSpec

type RouteSpec struct {
	PackageName          string
	Path                 string
	ServerImportPath     string
	OperationID          string
	Method               string
	InputType            string
	OutputType           string
	InputTypeKey         string
	OutputTypeKey        string
	ResponseContentTypes []string
	Dir                  string
	PackagePath          string
	InputBind            InputBindSpec
	OutputWrite          OutputWriteSpec
}

func LoadRoutes

func LoadRoutes(patterns []string) ([]RouteSpec, error)

func LoadRoutesInDir

func LoadRoutesInDir(dir string, patterns []string) ([]RouteSpec, error)

Jump to

Keyboard shortcuts

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