Get rid of checks when creating constructs. Check should handle this.

This commit is contained in:
2024-10-19 14:12:51 +02:00
parent 960889f9e7
commit 57db4178d0
21 changed files with 143 additions and 345 deletions

View File

@@ -1,7 +1,5 @@
package atom
import "fmt"
const (
InlineText = iota
InlineXHTML
@@ -17,17 +15,17 @@ type Content interface {
}
// NewContent creates a new Content. It returns a Content and an error.
func NewContent(contentType int, mediaType string, content any) (Content, error) {
func NewContent(contentType int, mediaType string, content any) Content {
switch contentType {
case 0:
return newInlineTextContent(mediaType, content)
return newInlineTextContent(mediaType, content.(string))
case 1:
return newInlineXHTMLContent(mediaType, content)
return newInlineXHTMLContent(mediaType, content.(*XHTMLDiv))
case 2:
return newInlineOtherContent(mediaType, content)
case 3:
return newOutOfLineContent(mediaType, content)
return newOutOfLineContent(mediaType, content.(string))
default:
return nil, fmt.Errorf("error creating new content: %v is not a valid text type", contentType)
return nil
}
}