FormatMessage formats the message using the given attributes.
(attributes map[string]any)
| 20 | |
| 21 | // FormatMessage formats the message using the given attributes. |
| 22 | func (d *Definition) FormatMessage(attributes map[string]any) string { |
| 23 | if d == nil { |
| 24 | return "" |
| 25 | } |
| 26 | if len(attributes) == 0 { |
| 27 | return d.messageFormat |
| 28 | } |
| 29 | parsedMessageFormat := d.parsedMessageFormat |
| 30 | if parsedMessageFormat == nil { |
| 31 | parsedMessageFormat, _ = formatter.Parse(d.messageFormat) |
| 32 | } |
| 33 | if parsedMessageFormat != nil { |
| 34 | formatted, err := parsedMessageFormat.FormatMap(attributes) |
| 35 | if err == nil { |
| 36 | return formatted |
| 37 | } |
| 38 | } |
| 39 | return d.messageFormat |
| 40 | } |
no test coverage detected