Added more error handling and necessary functions
This commit is contained in:
@@ -11,14 +11,25 @@ type ExtensionElement struct {
|
||||
}
|
||||
|
||||
// NewExtensionElement creates a new ExtensionElement. It returns a
|
||||
// *ExtensionElement.
|
||||
func NewExtensionElement(name string, value any) *ExtensionElement {
|
||||
return &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}
|
||||
// *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
|
||||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
||||
if e.Value == nil {
|
||||
return errors.New("value element of extension empty")
|
||||
}
|
||||
|
Reference in New Issue
Block a user