tmplrender

package
v3.0.0-rc72 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tmplrender renders a Go template from the cluster data an events stream keeps, and from the values fetched from the api no event carries: the datastore keys, the evaluated keywords, the resource informations.

A render records each read it makes, the events telling it may have changed, and its fingerprint: a watcher subscribes to these events, and renders again when a fingerprint changes. The reads are recorded as the template executes, so the ones under a condition, in a range, or of a computed name, are the ones the data led to.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is the error of a fetch of a value that does not exist.

Functions

func Changed

func Changed(reads []Read, st *State) []string

Changed returns the ids of the reads whose fingerprint in st is not the one they had at the render.

func ResourceInfoID

func ResourceInfoID(path, node string) string

ResourceInfoID is the key of the checksum of the resource information of the instance of path on node in State.ResourceInfo.

Types

type Fetcher

type Fetcher interface {
	// DataKey returns the decoded value of the key name of the
	// datastore p, ErrNotFound when the datastore or the key does
	// not exist.
	DataKey(ctx context.Context, p naming.Path, name string) ([]byte, error)

	// DataKeyNames returns the names of the keys of the datastore
	// p, ErrNotFound when it does not exist.
	DataKeyNames(ctx context.Context, p naming.Path) ([]string, error)

	// ConfigValue returns the value of the keyword kw of the object
	// p evaluated as the node evaluates it, or as the node serving
	// the api does when node is empty.
	ConfigValue(ctx context.Context, p naming.Path, kw, node string) (string, error)

	// ResourceInfo returns the value of the key of the information
	// of the resource rid of the object p on the node.
	ResourceInfo(ctx context.Context, p naming.Path, node, rid, key string) (string, error)
}

Fetcher reads the values no event carries: a datastore key, the value of a keyword as a node evaluates it, a resource information. They are fetched when a render reads them, the events only telling they changed.

type Item

type Item = map[string]any

Item is a thing a template reads from the cluster data: an object, an instance, a node, a resource, a network, by the json names of its fields, in snake case, as the api names them.

type Read

type Read struct {
	// ID names the read, as the template wrote it: avail
	// prod/svc/web.
	ID string

	// Kinds are the kinds of the events telling the read may have
	// changed.
	Kinds []string

	// Selection is the path, or path pattern, of the objects the
	// read follows the events of. It is empty for a read of node
	// data, whose events name no object.
	Selection string

	// AllObjects is true for a read following the events of every
	// object, as a range with no selector.
	AllObjects bool
	// contains filtered or unexported fields
}

Read is a read of a render: the events telling what it read may have changed, and its fingerprint, of what it read, or of the version of what it fetched.

type Renderer

type Renderer struct {
	// Name names the template in its errors, as its file.
	Name string

	// Text is the template.
	Text string

	// Namespace is the namespace of the relative paths of the
	// template.
	Namespace string

	// Data is the data of the template, as .name reads it.
	Data map[string]any

	Fetcher Fetcher
}

Renderer renders a template.

func (*Renderer) Parse

func (t *Renderer) Parse() error

Parse checks the template parses, and uses no unknown function.

func (*Renderer) Render

func (t *Renderer) Render(ctx context.Context, st *State) (Result, error)

Render renders the template, reading the cluster data of st.

type Result

type Result struct {
	// Out is the rendered template, nil when the render failed.
	Out []byte

	// Reads are the reads of the render, the ones made before an
	// error included: a template failing on a missing object
	// watches the object, and renders again when it appears.
	Reads []Read

	// ReadsSecret is true when the render read a sec key.
	ReadsSecret bool
}

Result is a render.

type State

type State struct {
	Data *clusterdump.Data

	// ResourceInfo are the checksums of the resource informations
	// of the instances, by ResourceInfoID.
	ResourceInfo map[string]string
}

State is what a render reads besides the fetched values: the cluster data the events keep, as the node serving the events sees it, and the checksums of the resource informations, which no cluster data holds.

func NewState

func NewState(data *clusterdump.Data) *State

NewState returns a state on the cluster data data.

type Subscription

type Subscription struct {
	Kinds    []string
	Selector string
}

Subscription is the events a set of reads needs: the kinds, of the objects the selector selects, or of all of them when it is empty.

func SubscriptionOf

func SubscriptionOf(reads []Read) Subscription

SubscriptionOf returns the events the reads need.

func (Subscription) Equal

func (t Subscription) Equal(o Subscription) bool

Equal returns true when s and o ask the same events.

func (Subscription) Filters

func (t Subscription) Filters() []string

Filters returns the filters of an events stream asking the events of s.

Jump to

Keyboard shortcuts

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