template

package
v0.1.0-alpha.20260716 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package template renders the templated fields used by the proxy against per-request values.

Templates are ordinary text/template source. They are bound to the context they render against:

  • ParseRouting yields a template over a RoutingContext (local namespace and metadata), used while routing rules choose an upstream. The remote namespace is not available here because translation is defined per upstream.
  • ParseUpstream yields a template over an UpstreamContext (local and remote namespace, and metadata), used to render the chosen upstream's hostPort and serverName.

A reference to a field absent from the bound context (such as RemoteNamespace in a routing template) fails at parse time. A reference to an absent metadata key renders as the empty string.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RoutingContext

type RoutingContext struct {
	LocalNamespace string
	Metadata       map[string]string
}

RoutingContext is available when evaluating routing rules, before an upstream has been selected. It deliberately omits the remote namespace: namespace translation is defined per upstream, so the remote name is not known until routing has chosen one.

type Template

type Template[T any] struct {
	// contains filtered or unexported fields
}

Template is a compiled template bound to the context type T it renders against. Construct one with ParseRouting or ParseUpstream.

func Must

func Must[T any](t *Template[T], err error) *Template[T]

Must returns t or panics if err is non-nil. It wraps a Parse call for package-level variables and tests where an invalid template is a programming error.

func ParseRouting

func ParseRouting(s string) (*Template[RoutingContext], error)

ParseRouting compiles s into a Template rendered against a RoutingContext. A reference to a field absent from that context (such as RemoteNamespace) fails here rather than at request time.

func ParseUpstream

func ParseUpstream(s string) (*Template[UpstreamContext], error)

ParseUpstream compiles s into a Template rendered against an UpstreamContext.

func (*Template[T]) Render

func (t *Template[T]) Render(ctx T) (string, error)

Render evaluates the template against ctx. A reference to an absent metadata key renders as the empty string.

func (*Template[T]) String

func (t *Template[T]) String() string

String returns the raw template source.

type UpstreamContext

type UpstreamContext struct {
	LocalNamespace  string
	RemoteNamespace string
	Metadata        map[string]string
}

UpstreamContext is available when rendering an upstream's hostPort and serverName, after routing has selected the upstream and the remote namespace is known.

Jump to

Keyboard shortcuts

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