generator

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package generator provides code generation for automatic route registration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(routesDir string) error

Generate scans the routes directory and generates registration code.

func GenerateTypeScriptDefinitions

func GenerateTypeScriptDefinitions(routesDir string) error

GenerateTypeScriptDefinitions scans Go structs in the routes directory to generate a types.d.ts file.

Types

type FuncParam

type FuncParam struct {
	Name string
	Type string
}

FuncParam represents a function parameter.

type RouteInfo

type RouteInfo struct {
	FilePath     string      // Relative path to .templ file
	URLPath      string      // URL path (e.g., /blog/:id)
	ComponentFn  string      // Component function name (e.g., BlogPage)
	IsLayout     bool        // True if this is a layout file
	IsDynamic    bool        // True if route has dynamic segments
	DynamicParam string      // The dynamic parameter name if any
	Params       []FuncParam // Function parameters parsed from _templ.go
	RouteParams  []string    // Dynamic route parameters extracted from URL path (e.g., ["id"] from /blog/:id)
	PackageName  string      // Package name for this route (e.g., "routes" or "blog")
	ImportPath   string      // Import path for subdirectory packages
}

RouteInfo holds information about a discovered route.

type RouteTypeScriptGenerator

type RouteTypeScriptGenerator struct {
	// contains filtered or unexported fields
}

RouteTypeScriptGenerator generates type-safe route helpers for TypeScript.

func NewRouteTypeScriptGenerator

func NewRouteTypeScriptGenerator(routes []RouteInfo, modulePath string) *RouteTypeScriptGenerator

NewRouteTypeScriptGenerator creates a new route TypeScript generator.

func (*RouteTypeScriptGenerator) GenerateRoutesFile

func (g *RouteTypeScriptGenerator) GenerateRoutesFile(outputDir string) error

GenerateRoutesFile generates a comprehensive routes.ts file with type-safe helpers.

Jump to

Keyboard shortcuts

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