generator

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package generator provides code generation for Fuego projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenerationWarning added in v0.9.0

type GenerationWarning struct {
	File    string
	Message string
}

GenerationWarning represents a warning during route generation.

type LayoutRegistration added in v0.4.0

type LayoutRegistration struct {
	ImportPath  string // Full import path for the generated _templ.go package
	ImportAlias string // Alias for the import
	Package     string // Package name
	PathPrefix  string // Path prefix this layout applies to
	FilePath    string // Source file path (layout.templ)
}

LayoutRegistration holds information for layout registration.

type LoaderConfig added in v0.11.3

type LoaderConfig struct {
	Path     string // Path relative to app directory (e.g., "dashboard", "users/_id")
	DataType string // Name of the data type (e.g., "DashboardData")
	AppDir   string // App directory (default: "app")
}

LoaderConfig holds configuration for generating a loader.

type LoaderRegistration added in v0.11.3

type LoaderRegistration struct {
	ImportPath  string // Full import path
	ImportAlias string // Alias for the import
	Package     string // Package name
	FilePath    string // Source file path (loader.go)
	ReturnType  string // Return type of the Loader function
	Dir         string // Directory containing the loader
}

LoaderRegistration holds information for a data loader.

type MiddlewareConfig

type MiddlewareConfig struct {
	Name     string // Middleware name (e.g., "auth")
	Path     string // Path prefix (e.g., "api/protected")
	Template string // Template name (auth, logging, timing, cors, blank)
	AppDir   string // App directory (default: "app")
}

MiddlewareConfig holds configuration for middleware generation.

type MiddlewareRegistration added in v0.3.5

type MiddlewareRegistration struct {
	ImportPath  string // Full import path
	ImportAlias string // Alias for the import
	Package     string // Package name
	PathPrefix  string // Path prefix the middleware applies to
	FilePath    string // Source file path
}

MiddlewareRegistration holds information for middleware registration.

type PageConfig

type PageConfig struct {
	Path       string // Page path (e.g., "dashboard")
	AppDir     string // App directory (default: "app")
	WithLayout bool   // Create a layout.templ alongside the page
}

PageConfig holds configuration for page generation.

type PageParam added in v0.9.0

type PageParam struct {
	Name     string // Parameter name (e.g., "slug")
	Type     string // Parameter type (e.g., "string")
	FromPath bool   // True if this param comes from URL path
}

PageParam represents a parameter in a Page() templ function.

type PageRegistration added in v0.4.0

type PageRegistration struct {
	ImportPath  string // Full import path for the generated _templ.go package
	ImportAlias string // Alias for the import
	Package     string // Package name
	Pattern     string // Route pattern (e.g., "/about", "/dashboard/settings")
	Title       string // Page title
	FilePath    string // Source file path (page.templ)

	// Dynamic page support
	Params         []PageParam // Parameters extracted from templ Page() signature
	URLParams      []string    // Parameter names extracted from URL path (e.g., _slug -> "slug")
	HasParams      bool        // True if Page() accepts parameters
	ParamSignature string      // Original signature from templ file (for comments)

	// Data loader support
	HasLoader        bool   // True if a loader.go exists in the same directory
	LoaderImportPath string // Import path for the loader
	LoaderPackage    string // Package name for the loader
}

PageRegistration holds information for page registration.

type ParamInfo

type ParamInfo struct {
	Name       string
	IsCatchAll bool
	IsOptional bool
}

ParamInfo holds information about a route parameter

type ProxyConfig

type ProxyConfig struct {
	Template string // Template name (auth-check, rate-limit, maintenance, redirect-www, blank)
	AppDir   string // App directory (default: "app")
}

ProxyConfig holds configuration for proxy generation.

type ProxyRegistration added in v0.3.5

type ProxyRegistration struct {
	ImportPath  string // Full import path
	ImportAlias string // Alias for the import
	Package     string // Package name
	FilePath    string // Source file path
	HasConfig   bool   // Whether ProxyConfig is defined
}

ProxyRegistration holds information for proxy registration.

type Result

type Result struct {
	Files   []string `json:"files"`
	Pattern string   `json:"pattern,omitempty"`
}

Result holds the result of a generation operation.

func GenerateLoader added in v0.11.3

func GenerateLoader(cfg LoaderConfig) (*Result, error)

GenerateLoader generates a loader.go file.

func GenerateMiddleware

func GenerateMiddleware(cfg MiddlewareConfig) (*Result, error)

GenerateMiddleware generates a middleware file.

func GeneratePage

func GeneratePage(cfg PageConfig) (*Result, error)

GeneratePage generates a page.templ file.

func GenerateProxy

func GenerateProxy(cfg ProxyConfig) (*Result, error)

GenerateProxy generates a proxy.go file.

func GenerateRoute

func GenerateRoute(cfg RouteConfig) (*Result, error)

GenerateRoute generates a route file with handlers.

func GenerateRoutesFile added in v0.3.5

func GenerateRoutesFile(cfg RoutesGenConfig) (*Result, error)

GenerateRoutesFile generates the fuego_routes.go file that registers all routes.

func ScanAndGenerateRoutes added in v0.3.5

func ScanAndGenerateRoutes(appDir, outputPath string) (*Result, error)

ScanAndGenerateRoutes scans the app directory and generates the routes file.

type RouteConfig

type RouteConfig struct {
	Path    string   // Route path (e.g., "users/_id")
	Methods []string // HTTP methods (e.g., ["GET", "PUT", "DELETE"])
	AppDir  string   // App directory (default: "app")
}

RouteConfig holds configuration for route generation.

type RouteConflict added in v0.11.3

type RouteConflict struct {
	Directory   string
	PageFile    string
	RouteFile   string
	Pattern     string
	HasRouteGet bool // True if route.go has a Get() handler
}

RouteConflict represents a conflict between page.templ and route.go

type RouteRegistration added in v0.3.5

type RouteRegistration struct {
	ImportPath  string // Full import path for the package
	ImportAlias string // Alias for the import (to avoid conflicts)
	Package     string // Package name
	Method      string // HTTP method (GET, POST, etc.)
	Pattern     string // Route pattern (/api/users/{id})
	Handler     string // Handler function name (Get, Post, etc.)
	FilePath    string // Source file path (for comments)
}

RouteRegistration holds information needed to generate route registration code.

type RoutesGenConfig added in v0.3.5

type RoutesGenConfig struct {
	ModuleName  string                   // Go module name (from go.mod)
	AppDir      string                   // App directory (default: "app")
	OutputPath  string                   // Output file path (default: "fuego_routes.go")
	Routes      []RouteRegistration      // Discovered routes
	Middlewares []MiddlewareRegistration // Discovered middlewares
	Proxy       *ProxyRegistration       // Discovered proxy (optional)
	Pages       []PageRegistration       // Discovered pages
	Layouts     []LayoutRegistration     // Discovered layouts
	Loaders     []LoaderRegistration     // Discovered data loaders
}

RoutesGenConfig holds configuration for generating the routes file.

Jump to

Keyboard shortcuts

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