Documentation
¶
Index ¶
- func ClearCache()
- func ExtractPropertyNames(template string) []string
- func ExtractPropertyNamesFromTemplate(tmpl *MessageTemplate) []string
- func ValidateTemplate(template string) error
- type CapturingHint
- type MessageTemplate
- type MessageTemplateToken
- type PropertyToken
- type TextToken
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractPropertyNames ¶
ExtractPropertyNames returns all property names from a template.
func ExtractPropertyNamesFromTemplate ¶
func ExtractPropertyNamesFromTemplate(tmpl *MessageTemplate) []string
ExtractPropertyNamesFromTemplate extracts property names from an already parsed template.
func ValidateTemplate ¶ added in v0.5.0
ValidateTemplate validates a message template and returns any errors found. This is used for runtime validation and selflog instrumentation.
Types ¶
type CapturingHint ¶ added in v0.6.0
type CapturingHint int
CapturingHint specifies how a property should be captured.
const ( // Default capturing uses Go's default string conversion (e.g., fmt.Sprintf("%v", value)). Default CapturingHint = iota // Stringify forces string conversion. Stringify // Capture captures object structure. Capture // AsScalar treats as scalar value. AsScalar )
type MessageTemplate ¶
type MessageTemplate struct {
// Raw is the original template string.
Raw string
// Tokens are the parsed tokens from the template.
Tokens []MessageTemplateToken
}
MessageTemplate represents a parsed message template.
func Parse ¶
func Parse(template string) (*MessageTemplate, error)
Parse parses a message template string into a MessageTemplate.
func ParseCached ¶
func ParseCached(template string) (*MessageTemplate, error)
ParseCached parses a template with caching to avoid repeated allocations.
type MessageTemplateToken ¶
type MessageTemplateToken interface {
// Render returns the string representation of the token using the provided properties.
Render(properties map[string]any) string
}
MessageTemplateToken represents a single token in a message template.
type PropertyToken ¶
type PropertyToken struct {
// PropertyName is the name of the property.
PropertyName string
// Capturing specifies how the property should be captured.
Capturing CapturingHint
// Format specifies the format string, if any.
Format string
// Alignment specifies text alignment, if any.
Alignment int
}
PropertyToken represents a property placeholder in a message template.
type TextToken ¶
type TextToken struct {
// Text is the literal text content.
Text string
}
TextToken represents literal text in a message template.
type ValidationError ¶ added in v0.5.0
ValidationError represents a template validation error
func (ValidationError) Error ¶ added in v0.5.0
func (e ValidationError) Error() string