Help us shape the future of Go! Take the 2026 Go Developer Survey

templateengine

package
v1.321.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

SPDX-FileCopyrightText: 2025 Forkbomb BV

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-FileCopyrightText: 2025 Forkbomb BV

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-FileCopyrightText: 2025 Forkbomb BV

SPDX-License-Identifier: AGPL-3.0-or-later

Package templateengine provides functionality for rendering templates

SPDX-FileCopyrightText: 2025 Forkbomb BV

SPDX-License-Identifier: AGPL-3.0-or-later

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Funcs

func Funcs() template.FuncMap

Funcs returns the sprout functions available to Credimi templates.

It is sprout's "all" group without the env registry: templates can reach tenant-controlled input, and env/expandEnv would expose the process environment (server secrets) to whoever writes the template.

func GetPlaceholders

func GetPlaceholders(readers []io.Reader, names []string) (map[string]interface{}, error)

GetPlaceholders processes a list of template readers and their corresponding names to extract placeholder metadata and organize it into normalized and specific fields.

func LoadYAML

func LoadYAML(filename string, v any) error

func ParseEudiwInput

func ParseEudiwInput(input, defaultFile string) ([]byte, error)

ParseEudiwInput parses a YAML template file and updates both "id" and "nonce" fields using the provided input as a prefix for the credimi_id values. It mirrors the logic of ParseEwcInput but operates on two fields.

func ParseEwcInput

func ParseEwcInput(input, defaultFile string) ([]byte, error)

func ParseOpenidnetInput

func ParseOpenidnetInput(input, defaultFile, configFile string) ([]byte, error)

func RenderTemplate

func RenderTemplate(reader io.Reader, data map[string]interface{}) (string, error)

RenderTemplate takes a reader containing a template and a data map, renders the template using the provided data, and returns the resulting string. It also preprocesses the template to handle custom placeholders and metadata extraction.

func ValidateVariant

func ValidateVariant(variant map[string]string, config Config) error

Types

type Config

type Config struct {
	VariantOrder   []string                        `json:"variant_order"   yaml:"variant_order"`
	VariantKeys    map[string][]string             `json:"variant_keys"    yaml:"variant_keys"`
	OptionalFields map[string]map[string]FieldRule `json:"optional_fields" yaml:"optional_fields"`
}

type FieldRule

type FieldRule struct {
	Values   map[string][]string `json:"values"   yaml:"values"`
	Template string              `json:"template" yaml:"template"`
}

type PlaceholderMetadata

type PlaceholderMetadata struct {
	CredimiID    string          `json:"credimi_id"`
	FieldID      string          `json:"field_id"`
	FieldLabel   string          `json:"field_label"`
	FieldDesc    string          `json:"field_description"`
	FieldDefault interface{}     `json:"field_default_value"`
	FieldType    TypeOfFieldType `json:"field_type"`
	FieldOptions []string        `json:"field_options"`
}

PlaceholderMetadata holds metadata for a placeholder in a template. It matches the placeholderInput struct.

func (*PlaceholderMetadata) GetDefaultValue

func (p *PlaceholderMetadata) GetDefaultValue() string

GetDefaultValue returns the default value of the placeholder, if the original value is a string return a string, if is an object return a json string

type TypeOfFieldType

type TypeOfFieldType string
const (
	TypeOfFieldTypeString  TypeOfFieldType = "string"
	TypeOfFieldTypeObject  TypeOfFieldType = "object"
	TypeOfFieldTypeOptions TypeOfFieldType = "options"
)

Jump to

Keyboard shortcuts

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