Documentation
¶
Overview ¶
Package templates provides Nix flake template rendering for build strategies.
Index ¶
- Variables
- func FormatLdflagsForNix(ldflags string) string
- func GetTemplateForStrategy(strategy models.BuildStrategy, config models.BuildConfig) string
- type DefaultTemplateEngine
- func (e *DefaultTemplateEngine) ListTemplates() []string
- func (e *DefaultTemplateEngine) Render(ctx context.Context, templateName string, data TemplateData) (string, error)
- func (e *DefaultTemplateEngine) RenderAndValidate(ctx context.Context, templateName string, data TemplateData) (string, error)
- func (e *DefaultTemplateEngine) Validate(ctx context.Context, flakeContent string) error
- func (e *DefaultTemplateEngine) ValidateSyntax(flakeContent string) error
- type TemplateData
- type TemplateEngine
Constants ¶
This section is empty.
Variables ¶
var ( ErrTemplateNotFound = fmt.Errorf("template not found") ErrTemplateRenderFailed = fmt.Errorf("failed to render template") ErrInvalidFlakeSyntax = fmt.Errorf("generated flake has invalid syntax") )
Errors for template operations - kept for backward compatibility.
Functions ¶
func FormatLdflagsForNix ¶
FormatLdflagsForNix converts a space-separated ldflags string into Nix list format. It handles quoted strings and -X flags with values correctly. e.g., "-s -w -X main.version=1.0" -> ""-s" "-w" "-X main.version=1.0"" **Validates: Requirements 18.2**
func GetTemplateForStrategy ¶
func GetTemplateForStrategy(strategy models.BuildStrategy, config models.BuildConfig) string
GetTemplateForStrategy returns the appropriate template name for a build strategy.
Types ¶
type DefaultTemplateEngine ¶
type DefaultTemplateEngine struct {
// contains filtered or unexported fields
}
DefaultTemplateEngine is the default implementation of TemplateEngine.
func NewTemplateEngine ¶
func NewTemplateEngine() (*DefaultTemplateEngine, error)
NewTemplateEngine creates a new DefaultTemplateEngine with embedded templates.
func (*DefaultTemplateEngine) ListTemplates ¶
func (e *DefaultTemplateEngine) ListTemplates() []string
ListTemplates returns available template names.
func (*DefaultTemplateEngine) Render ¶
func (e *DefaultTemplateEngine) Render(ctx context.Context, templateName string, data TemplateData) (string, error)
Render generates a flake.nix from a template.
func (*DefaultTemplateEngine) RenderAndValidate ¶
func (e *DefaultTemplateEngine) RenderAndValidate(ctx context.Context, templateName string, data TemplateData) (string, error)
RenderAndValidate renders a template and validates the output. This is a convenience method that combines Render and Validate.
func (*DefaultTemplateEngine) Validate ¶
func (e *DefaultTemplateEngine) Validate(ctx context.Context, flakeContent string) error
Validate checks if generated flake.nix is syntactically valid using nix flake check.
func (*DefaultTemplateEngine) ValidateSyntax ¶
func (e *DefaultTemplateEngine) ValidateSyntax(flakeContent string) error
ValidateSyntax performs a basic syntax check on the flake content without running nix. This is faster than full validation and catches common template errors.
type TemplateData ¶
type TemplateData struct {
AppName string
Version string
Framework models.Framework
EntryPoint string
BuildCommand string
StartCommand string
Config models.BuildConfig
DetectionResult *models.DetectionResult
System string
DatabaseType string
DatabaseVersion string
}
TemplateData contains data passed to templates.
type TemplateEngine ¶
type TemplateEngine interface {
// Render generates a flake.nix from a template.
Render(ctx context.Context, templateName string, data TemplateData) (string, error)
// Validate checks if generated flake.nix is syntactically valid.
Validate(ctx context.Context, flakeContent string) error
// ListTemplates returns available template names.
ListTemplates() []string
}
TemplateEngine renders Nix flake templates.