Use generics for Add and Delete Methods
This commit is contained in:
@@ -19,23 +19,15 @@ func newCommonAttributes() *CommonAttributes {
|
||||
|
||||
// AddAttribute adds the attribute to the CommonAttributes.
|
||||
func (c *CommonAttributes) AddAttribute(name, value string) {
|
||||
if c.UndefinedAttributes == nil {
|
||||
c.UndefinedAttributes = make([]*xml.Attr, 1)
|
||||
c.UndefinedAttributes[0] = &xml.Attr{Name: xml.Name{Local: name}, Value: value}
|
||||
} else {
|
||||
c.UndefinedAttributes = append(c.UndefinedAttributes, &xml.Attr{Name: xml.Name{Local: name}, Value: value})
|
||||
}
|
||||
addToSlice(c.UndefinedAttributes, &xml.Attr{Name: xml.Name{Local: name}, Value: value})
|
||||
}
|
||||
|
||||
// DeleteAttribute deletes the attribute from the CommonAttributes. It return an
|
||||
// error.
|
||||
func (c *CommonAttributes) DeleteAttribute(id int) error {
|
||||
length := len(c.UndefinedAttributes)
|
||||
if id > length {
|
||||
return fmt.Errorf("error deleting undefined attribute from common attributes %v: id %v out of range %v", c, id, length)
|
||||
if err := deleteFromSlice(c.UndefinedAttributes, id); err != nil {
|
||||
return fmt.Errorf("error deleting undefined attribute %v from common attributes %v: %v", id, c, err)
|
||||
}
|
||||
|
||||
c.UndefinedAttributes = append(c.UndefinedAttributes[:id], c.UndefinedAttributes[id+1:]...)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user