Documentation
¶
Overview ¶
Package tmpl parses and renders response templates: JSON bodies and header values that hold {{uuid}}, {{now}}, {{path.NAME}} and {{body.PATH}} placeholders.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PathValues ¶
PathValues matches an escaped request path against template segment by segment, path-unescaping each matched value. Returns nil when the segment counts differ.
Types ¶
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a parsed response template. It is immutable after Parse, so Render is safe for concurrent use.
func Parse ¶
Parse checks body (JSON, may be empty) and header values. The pathNames are the parameter names in the operation's template; {{path.X}} with X not in it is an error.
func (*Template) BodyPointers ¶
BodyPointers returns the JSON pointers ("/a/0/b") of every string value that is a single {{body.*}} placeholder, sorted. Such a value takes the type of the request field when served.
func (*Template) Render ¶
Render returns the rendered body (nil when the template body was empty) and headers.
func (*Template) TextPointers ¶
TextPointers returns the JSON pointers, sorted, of every other templated string value whose text depends on the request: it embeds a {{body.*}} placeholder or names a path parameter in unresolved. Such a value is always a string, but its text is only known when served.
type Vars ¶
type Vars struct {
UUID string
Now time.Time
Path map[string]string
Body []byte
// Sample marks a registration-time render: a whole-string body
// placeholder with no value renders "" in place instead of being dropped.
Sample bool
}
Vars are the per-call inputs. Body is the raw request body (may be nil or non-JSON).