distrogen

package
v0.42.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package distrogen renders package definitions - a distro.yaml and whatever files sit beside it - from Go templates.

It is the generator both callers share: `cargoship dev render`, where an operator brings their own template and a values file, and mage's example targets, which derive their data from engine pins and render the committed examples under example/. The templates are evaluated with the same function map a package's own values templates get (pkg/helmvalues), so a template written for one renders the same way in the other.

Rendering and writing are separate steps because a caller may need the bytes first: the example generator drops a rendered content manifest that turns out to declare nothing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckOutputs

func CheckOutputs(dir string, files []File) error

CheckOutputs reports whether rendering files into dir would write somewhere it must not.

Two of these have eaten a file in practice. An output that lands on one of the templates being rendered overwrites it with its own output - `dev render -t ./distro.yaml` with no --out is the whole of it, since reading happens before writing and nothing fails. Two templates whose names collide write to one path, and the first result is lost behind the second while both are reported as rendered.

Called before Render rather than before Write so that nothing is read, let alone written, when the request cannot be satisfied.

func ValidateDistro

func ValidateDistro(source string, content []byte) error

ValidateDistro checks rendered bytes against the generated package schema, the same check `cargoship validate` applies to a definition already on disk. source names the document in the problems it reports.

func Write

func Write(dir string, rendered []Rendered) ([]string, error)

Write writes rendered output into dir, creating it if it does not exist, and returns the paths it wrote.

Types

type File

type File struct {
	Template string // path to the template
	Name     string // output name; "" means the template's base name without .tmpl
}

File is one template and the name it renders to.

func (File) OutputName

func (f File) OutputName() string

OutputName is the name a file renders to: what it declares, or its template's base name without the .tmpl suffix.

type Rendered

type Rendered struct {
	Name    string
	Content []byte
}

Rendered is one template's output, before anything has been written.

func Render

func Render(files []File, data any, opts ...helmvalues.Option) ([]Rendered, error)

Render evaluates each file's template against data. The returned slice is in the order the files were given.

Jump to

Keyboard shortcuts

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