Create function to safely create new text construct
This commit is contained in:
parent
64a2d6b583
commit
2d1d95502f
17
text.go
17
text.go
@ -1,6 +1,23 @@
|
|||||||
package atomfeed
|
package atomfeed
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type Text interface {
|
type Text interface {
|
||||||
Check() error
|
Check() error
|
||||||
IsText() bool
|
IsText() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewText(textType, content string) (Text, error) {
|
||||||
|
switch textType {
|
||||||
|
case "text", "html":
|
||||||
|
return &PlainText{Type: textType, Text: content}, nil
|
||||||
|
case "xhtml":
|
||||||
|
return &XHTMLText{Type: textType, XHTMLDiv: content}, nil
|
||||||
|
case "":
|
||||||
|
return &PlainText{Type: "text", Text: content}, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("%v is not a valid text type", textType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user