Set sets the value of the attribute with the given name. If the attribute does not exist, it is created.
(name Name, value string)
| 53 | // Set sets the value of the attribute with the given name. |
| 54 | // If the attribute does not exist, it is created. |
| 55 | func (a *Attributes) Set(name Name, value string) { |
| 56 | // Initialize the map if it is nil |
| 57 | if a.m == nil { |
| 58 | a.m = make(map[Name]*Attribute) |
| 59 | } |
| 60 | |
| 61 | // If attribute exists, update its value |
| 62 | if attr, exists := a.m[name]; exists { |
| 63 | attr.Value = value |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | // Otherwise, create a new attribute |
| 68 | attr := &Attribute{Name: name, Value: value} |
| 69 | a.m[name] = attr |
| 70 | a.s = append(a.s, attr) |
| 71 | } |
| 72 | |
| 73 | // SetByString is like Set but accepts a string name. |
| 74 | func (a *Attributes) SetByString(name, value string) { |