From 7764589dd3a2df61379e4cb02d36eca8daec4868 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Tue, 15 Oct 2024 21:14:30 +0200 Subject: [PATCH] Add NewContent --- content.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/content.go b/content.go index 8e07372..e8112f9 100644 --- a/content.go +++ b/content.go @@ -1,8 +1,34 @@ package atomfeed +import ( + "fmt" +) + +const ( + InlineText = iota + InlineXHTML + InlineOther + OutOfLine +) + type Content interface { isContent() bool hasSRC() bool getType() string Check() error } + +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("%v is not a valid text type", contentType) + } +}