templates

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package templates provides the built-in project scaffolds ("presets") and the composable service blocks ("blocks", the builder/skládačka) for the Projects feature, plus the rendering that turns either into concrete project files.

Built-ins are embedded from catalog/; the API layer merges these with user-saved presets/blocks loaded from the store. Both presets and blocks carry optional Variables that are filled in (and secrets generated) at create time and rendered with text/template — the same mechanism as webhook bodies.

Index

Constants

View Source
const (
	SourceBuiltin = "builtin"
	SourceUser    = "user"
	SourceRemote  = "remote"
)

Source identifies where a preset/block came from. "remote" is reserved for a future catalog provider that fetches from an external API.

Variables

This section is empty.

Functions

func AnchorNames

func AnchorNames(content string) []string

AnchorNames returns every YAML anchor (`&name`) declared in a fragment's content (in order, de-duplicated) — used to wire `<<: *name` merges. Comment lines are skipped so a `# … &x …` note can't be mistaken for an anchor.

func ResolveVars

func ResolveVars(decl []Variable, provided map[string]string) (map[string]string, error)

ResolveVars merges provided values over the declared variables: a blank value falls back to Default, or to a generated secret when Generate is set. It errors if a non-generated variable ends up empty and had no default.

Types

type Block

type Block struct {
	ID          string     `json:"id"`
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Source      string     `json:"source"`
	Service     string     `json:"service"` // the service key in compose, e.g. "db"
	Variables   []Variable `json:"variables,omitempty"`
	Volumes     []string   `json:"volumes,omitempty"` // top-level named volumes to declare
	ServiceYAML string     `json:"serviceYaml,omitempty"`
	Files       []File     `json:"files,omitempty"` // sidecar files copied into the project
}

Block is a single compose service fragment for the builder. ServiceYAML holds the service body already indented two spaces under `services:`.

func BuiltinBlocks

func BuiltinBlocks() ([]Block, error)

BuiltinBlocks returns the embedded service blocks, sorted by name.

type File

type File struct {
	Path    string `json:"path"`
	Content string `json:"content"`
}

File is one file in a project scaffold (path is relative to the project root).

func AssembleCompose

func AssembleCompose(slug string, instances []Instance, fragments []Fragment, vars map[string]string) ([]File, error)

AssembleCompose builds the project files for a builder selection: a single compose.yml with any shared definitions (top-level YAML anchors) above services:, each instance's service (renamed to its key, with `<<: *anchor` merges injected and named volumes de-duplicated per instance), the top-level named volumes, and the sidecar files the blocks contribute. Built-in block YAML/sidecars are rendered with vars; fragments are copied literally so anchors/merge keys survive.

func Render

func Render(files []File, vars map[string]string) ([]File, error)

Render fills in the variables on a set of files via text/template, erroring on any template key that has no value (missingkey=error).

type Fragment

type Fragment struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Source      string `json:"source"`
	Content     string `json:"content,omitempty"`
}

Fragment is a top-level "shared definition" for the builder — a YAML anchor (e.g. `x-common: &common ...`) emitted above services: so any service can merge it with `<<: *common`. Content is copied literally (never rendered), so anchors and merge keys survive intact.

func BuiltinFragments

func BuiltinFragments() ([]Fragment, error)

BuiltinFragments returns the embedded shared definitions, sorted by name.

type Instance

type Instance struct {
	Block        Block
	Key          string   // service key in the output; defaults to Block.Service
	MergeAnchors []string // anchor names to inject as `<<: *name` at the top of the service
}

Instance is one service placed by the builder: a block under a chosen service key, optionally merging shared-definition anchors. Adding the same block twice (two instances, distinct keys) builds a cluster.

type Preset

type Preset struct {
	ID          string     `json:"id"`
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Source      string     `json:"source"`
	Variables   []Variable `json:"variables,omitempty"`
	Files       []File     `json:"files,omitempty"` // omitted from list responses, included on detail
}

Preset is a complete project scaffold (one or more files).

func BuiltinPresets

func BuiltinPresets() ([]Preset, error)

BuiltinPresets returns the embedded project presets, sorted by name.

type Variable

type Variable struct {
	Key      string `json:"key"`                // template key, e.g. "HttpPort"
	Label    string `json:"label"`              // human label for the form
	Default  string `json:"default,omitempty"`  // value used when the field is left blank
	Secret   bool   `json:"secret,omitempty"`   // masked in the UI, encrypted at rest
	Generate string `json:"generate,omitempty"` // "password" → autofill a random value when blank
}

Variable is a fill-in parameter declared by a preset or block.

Jump to

Keyboard shortcuts

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