atom/content.go

34 lines
715 B
Go
Raw Normal View History

2024-10-16 21:28:04 +02:00
package atom
2024-10-13 17:19:40 +02:00
2024-10-18 19:04:08 +02:00
import "fmt"
2024-10-15 21:14:30 +02:00
const (
InlineText = iota
InlineXHTML
InlineOther
OutOfLine
)
2024-10-13 17:19:40 +02:00
type Content interface {
2024-10-15 19:32:14 +02:00
isContent() bool
hasSRC() bool
getType() string
2024-10-13 17:19:40 +02:00
Check() error
}
2024-10-15 21:14:30 +02:00
2024-10-16 19:59:28 +02:00
// NewContent creates a new Content. It returns a Content and an error.
2024-10-15 21:14:30 +02:00
func NewContent(contentType int, mediaType string, content any) (Content, error) {
switch contentType {
case 0:
return newInlineTextContent(mediaType, content)
case 1:
return newInlineXHTMLContent(mediaType, content)
case 2:
return newInlineOtherContent(mediaType, content)
case 3:
return newOutOfLineContent(mediaType, content)
default:
return nil, fmt.Errorf("error creating new content: %v is not a valid text type", contentType)
2024-10-15 21:14:30 +02:00
}
}