helpers

package
v0.1.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package helpers provides shared utility functions for the controller layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractPostProcessorConfigs

func ExtractPostProcessorConfigs(cfg *config.Config) map[string][]templating.PostProcessorConfig

ExtractPostProcessorConfigs extracts post-processor configurations from all templates.

This includes post-processors for:

  • Main HAProxy configuration (haproxy.cfg)
  • Map file templates
  • General file templates
  • SSL certificate templates

Returns a map of template names to their post-processor configurations.

func NewEngineFromConfig

func NewEngineFromConfig(
	cfg *config.Config,
	globalFunctions map[string]templating.GlobalFunc,
	postProcessorConfigs map[string][]templating.PostProcessorConfig,
) (templating.Engine, error)

NewEngineFromConfig creates a template engine from configuration.

This is a convenience function that handles the common pattern of:

  1. Extracting templates from configuration
  2. Parsing the engine type from configuration
  3. Creating the template engine

All standard filters (sort_by, glob_match, b64decode, strip, trim, debug) and the fail() function are registered internally by each engine. Callers only need to pass custom filters/functions if they have additional ones beyond the standard set.

Parameters:

  • cfg: Configuration containing templates and engine settings
  • globalFunctions: Optional custom global functions. Can be nil (fail is auto-registered)
  • postProcessorConfigs: Optional post-processor configurations. Can be nil

Returns the initialized Engine or an error if initialization fails.

func NewEngineFromConfigWithOptions

func NewEngineFromConfigWithOptions(
	cfg *config.Config,
	globalFunctions map[string]templating.GlobalFunc,
	postProcessorConfigs map[string][]templating.PostProcessorConfig,
	options EngineOptions,
) (templating.Engine, error)

NewEngineFromConfigWithOptions creates a template engine with additional options.

This is the full-featured version of NewEngineFromConfig that accepts EngineOptions for controlling profiling and other engine-specific settings.

If postProcessorConfigs is nil, post-processors are automatically extracted from the configuration. Pass an explicit empty map to disable post-processing.

For Scriggo engines: Only entry points are compiled explicitly. Template snippets are discovered and compiled automatically when referenced via render/render_glob with inherit_context.

Types

type EngineOptions

type EngineOptions struct {
	// EnableProfiling enables include timing profiling for the engine.
	// When true, RenderWithProfiling() returns actual timing statistics.
	EnableProfiling bool
}

EngineOptions configures template engine creation.

type TemplateExtraction

type TemplateExtraction struct {
	// AllTemplates contains all template content (entry points + snippets).
	// This is provided to the template engine's filesystem so all templates are accessible.
	AllTemplates map[string]string

	// EntryPoints lists template names that should be compiled explicitly.
	// Only these are compiled; snippets are compiled on-demand.
	EntryPoints []string
}

TemplateExtraction contains templates and entry points extracted from configuration.

For Scriggo engines with inherit_context support, only entry points are compiled explicitly. Snippet templates are discovered and compiled automatically by Scriggo when referenced via render/render_glob statements.

func ExtractTemplatesFromConfig

func ExtractTemplatesFromConfig(cfg *config.Config) TemplateExtraction

ExtractTemplatesFromConfig extracts all templates from the configuration structure.

Returns:

  • AllTemplates: All template content (entry points + snippets)
  • EntryPoints: Templates that should be compiled explicitly (main config + auxiliary files)

Entry points are:

  • Main HAProxy configuration (haproxy.cfg)
  • Map file templates
  • General file templates
  • SSL certificate templates

Template snippets are NOT entry points - they are discovered and compiled automatically by Scriggo when referenced via render/render_glob statements with inherit_context.

Jump to

Keyboard shortcuts

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