tag

package
v0.500.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tag expands JaWS tag values into the comparable keys used to find elements during dirtying, broadcasts and event routing.

The runtime tag-comparability check in TagExpand is gated on deadlock.Debug, so it (and full statement coverage of this package) is only exercised when the tests run with the -race flag or -tags debug. Always test with -race.

Index

Constants

This section is empty.

Variables

View Source
var ErrIllegalTagType errIllegalTagType

ErrIllegalTagType is returned when a UI tag type is disallowed.

View Source
var ErrNotComparable errNotComparable

ErrNotComparable is returned when a UI object or tag is not comparable.

View Source
var ErrNotUsableAsTag errNotUsableAsTag

ErrNotUsableAsTag is returned when a value cannot be used as a tag.

It is also matchable as ErrNotComparable for backwards compatibility.

View Source
var ErrTooManyTags errTooManyTags

ErrTooManyTags is returned when tag expansion exceeds the recursion depth (maxTagDepth) or result count (maxTagCount) limits.

Functions

func FindTagGetter

func FindTagGetter(x any) (path string, tgType reflect.Type, found bool)

FindTagGetter searches x recursively for a nested TagGetter.

The search is bounded: it follows at most maxTagDepth levels of nesting and scans only the first maxHintScan elements of any array or slice. It is used only to enrich the ErrNotUsableAsTag diagnostic, so these bounds trade completeness for a cheap, terminating search.

func MustTagExpand

func MustTagExpand(ctx Context, tag any) []any

MustTagExpand calls TagExpand and either logs or panics if expansion fails.

When ctx is non-nil, expansion errors are passed to [Context.MustLog] and the partial result is returned. When ctx is nil, MustTagExpand panics.

func NewErrNotComparable

func NewErrNotComparable(x any) error

NewErrNotComparable returns ErrNotComparable if x is not comparable.

func NewErrNotUsableAsTag

func NewErrNotUsableAsTag(x any) error

NewErrNotUsableAsTag returns ErrNotUsableAsTag if x cannot be used as a tag.

func TagExpand

func TagExpand(ctx Context, tag any) ([]any, error)

TagExpand expands tag into a flat list of unique comparable tag values.

tag may be nil, a Tag, a slice of tags, a TagGetter or another comparable value. Primitive HTML/value types are rejected with ErrIllegalTagType to catch common accidental tags.

func TagString

func TagString(tag any) string

TagString returns a debug string for tag.

Types

type Context

type Context interface {
	// Initial returns the Request's initial HTTP request, or nil.
	Initial() (r *http.Request)
	// Get returns the JaWS session value for the key, or nil.
	Get(key string) any
	// Set sets the JaWS session value for the key.
	Set(key string, value any)
	// Context returns the Request's context.
	Context() (ctx context.Context)
	// Log sends an error to the Logger set in the Jaws.
	// Has no effect if the err is nil or the Logger is nil.
	// Returns err.
	Log(err error) error
	// MustLog sends an error to the Logger set in the Jaws or
	// panics with the given error if no Logger is set.
	// Has no effect if the err is nil.
	MustLog(err error)
}

Context is the request state made available while expanding tags.

type Tag

type Tag string

Tag is a simple comparable tag value.

type TagGetter

type TagGetter interface {
	JawsGetTag(ctx Context) any // Note that the Context may be nil
}

TagGetter exposes dynamic tags during TagExpand.

Jump to

Keyboard shortcuts

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