NewAttributes creates a new [Attributes] instance from the given attributes.
(attrs ...*Attribute)
| 19 | |
| 20 | // NewAttributes creates a new [Attributes] instance from the given attributes. |
| 21 | func NewAttributes(attrs ...*Attribute) *Attributes { |
| 22 | // If no attributes are provided, return an empty Attributes instance |
| 23 | if len(attrs) == 0 { |
| 24 | return &Attributes{} |
| 25 | } |
| 26 | |
| 27 | // Create a map for quick lookup |
| 28 | m := make(map[Name]*Attribute, len(attrs)) |
| 29 | for _, attr := range attrs { |
| 30 | m[attr.Name] = attr |
| 31 | } |
| 32 | |
| 33 | return &Attributes{ |
| 34 | s: attrs, |
| 35 | m: m, |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // Get retrieves the value of the attribute with the given name. |
| 40 | // It returns the value and true if the attribute exists, or an empty string and false otherwise. |
no outgoing calls
no test coverage detected