Added more error handling and necessary functions

This commit is contained in:
2024-10-19 12:28:09 +02:00
parent d4e7bce5e2
commit f4dfd6d060
22 changed files with 317 additions and 122 deletions

View File

@@ -1,6 +1,9 @@
package atom
import "fmt"
import (
"errors"
"fmt"
)
type PlainText struct {
*CommonAttributes
@@ -11,6 +14,15 @@ type PlainText struct {
// isText checks whether the PlainText is a Text. It returns a bool.
func (p *PlainText) isText() bool { return true }
// newPlainText creates a new PlainText. It returns a *PlainText and an error.
func newPlainText(textType, content string) (*PlainText, error) {
if content == "" {
return nil, errors.New("error creating new plain text: content string empty")
}
return &PlainText{Type: textType, Text: content}, nil
}
// Check checks the PlainText for incompatibilities with RFC4287. It returns an
// error.
func (p *PlainText) Check() error {