Documentation
¶
Index ¶
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.
Types ¶
type DestructuringHint ¶
type DestructuringHint int
DestructuringHint specifies how a property should be destructured.
const ( // Default destructuring uses ToString. Default DestructuringHint = iota // Stringify forces string conversion. Stringify // Destructure captures object structure. Destructure // 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.
func (*MessageTemplate) Render ¶
func (mt *MessageTemplate) Render(properties map[string]interface{}) string
Render generates the final message using the provided properties.
type MessageTemplateToken ¶
type MessageTemplateToken interface {
// Render returns the string representation of the token using the provided properties.
Render(properties map[string]interface{}) string
}
MessageTemplateToken represents a single token in a message template.
type PropertyToken ¶
type PropertyToken struct {
// PropertyName is the name of the property.
PropertyName string
// Destructuring specifies how the property should be destructured.
Destructuring DestructuringHint
// 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.
func (*PropertyToken) Render ¶
func (p *PropertyToken) Render(properties map[string]interface{}) string
Render returns the string representation of the property value.