Get rid of checks when creating constructs. Check should handle this.

This commit is contained in:
2024-10-19 14:12:51 +02:00
parent 960889f9e7
commit 57db4178d0
21 changed files with 143 additions and 345 deletions

View File

@@ -2,7 +2,7 @@ package atom
import (
"encoding/xml"
"errors"
"fmt"
)
type ExtensionElement struct {
@@ -11,27 +11,20 @@ type ExtensionElement struct {
}
// NewExtensionElement creates a new ExtensionElement. It returns a
// *ExtensionElement and an error.
func NewExtensionElement(name string, value any) (*ExtensionElement, error) {
if name == "" {
return nil, errors.New("error adding extension attribute: name string empty")
}
if value == "" {
return nil, errors.New("error adding extension attribute: value string empty")
}
return &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}, nil
// *ExtensionElement.
func NewExtensionElement(name string, value any) *ExtensionElement {
return &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}
}
// Check checks the ExtensionElement for incompatibilities with RFC4287. It
// returns an error.
func (e *ExtensionElement) Check() error {
if e.XMLName.Local == "" {
return errors.New("xml name of extension empty")
return fmt.Errorf("xml name of extension %v empty", e)
}
if e.Value == nil {
return errors.New("value element of extension empty")
return fmt.Errorf("value of extension %v empty", e)
}
return nil