codegen

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(tree *RouteTree, pkgName string) ([]byte, error)

Generate produces the generated Go source file containing type-safe route constructors and asset accessors from the given RouteTree.

func GenerateAssetsFile

func GenerateAssetsFile(entries []AssetEntry, pkgName string) ([]byte, error)

GenerateAssetsFile generates a Go source file with functions for each asset.

func GenerateRouteFile

func GenerateRouteFile(pkgName string) ([]byte, error)

GenerateRouteFile generates the route.go file containing the Route type and helper functions used by the generated route constructors.

func LoadPackages

func LoadPackages(dir, pattern string) ([]*packages.Package, error)

LoadPackages loads Go packages matching the pattern from the given directory. Returns packages that import thx along with their direct dependencies.

Types

type AssetEntry

type AssetEntry struct {
	// FilePath is the URL path (e.g. "/assets/app.js").
	FilePath string
	// FuncName is the Go function name (e.g. "AppJs").
	FuncName string
	// Hash is the truncated content hash for cache busting.
	Hash string
}

AssetEntry represents a static file with its path and content hash.

func ScanAssets

func ScanAssets(dir string, urlPrefix string) ([]AssetEntry, error)

ScanAssets scans a directory and returns asset entries with content hashes.

type AssetGroup

type AssetGroup struct {
	Name    string // derived from the FS variable name (e.g. "publicFS" → "PublicFS")
	Prefix  string
	Dir     string // absolute path to the directory on disk
	Entries []AssetEntry
}

AssetGroup represents a set of static assets served from one directory.

type PathParam

type PathParam struct {
	Name string
}

PathParam represents a named path parameter extracted from a route pattern.

type RouteEntry

type RouteEntry struct {
	Name       string
	Method     string
	Path       string
	PathParams []PathParam
	QueryType  *StructInfo
}

RouteEntry represents a single route with its HTTP method and path.

type RouteGroup

type RouteGroup struct {
	Name   string
	Prefix string
	Routes []RouteEntry
	Groups []RouteGroup
}

RouteGroup represents a group of routes under a common URL prefix.

type RouteTree

type RouteTree struct {
	Routes []RouteEntry
	Groups []RouteGroup
	Assets []AssetGroup
}

RouteTree is the top-level structure holding all extracted route information.

func Extract

func Extract(pkgs []*packages.Package) (*RouteTree, error)

Extract analyzes the given packages and returns a RouteTree containing all discovered routes, groups, and static asset definitions.

type StructField

type StructField struct {
	Name      string
	Type      string
	SchemaTag string
}

StructField represents a single field in a query parameter struct.

type StructInfo

type StructInfo struct {
	Fields []StructField
}

StructInfo holds metadata about a query parameter struct's fields.

Jump to

Keyboard shortcuts

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