Check type assertions for content types

This commit is contained in:
2025-10-07 19:07:33 +02:00
parent 9ab48787d4
commit a65920aa70

View File

@@ -21,13 +21,22 @@ type Content interface {
func NewContent(contentType int, mediaType string, content any) Content { func NewContent(contentType int, mediaType string, content any) Content {
switch contentType { switch contentType {
case 0: case 0:
return newInlineTextContent(mediaType, content.(string)) if stringContent, ok := content.(string); ok {
return newInlineTextContent(mediaType, stringContent)
}
return nil
case 1: case 1:
return newInlineXHTMLContent(mediaType, content.(*XHTMLDiv)) if xhtmlDivContent, ok := content.(*XHTMLDiv); ok {
return newInlineXHTMLContent(mediaType, xhtmlDivContent)
}
return nil
case 2: case 2:
return newInlineOtherContent(mediaType, content) return newInlineOtherContent(mediaType, content)
case 3: case 3:
return newOutOfLineContent(mediaType, content.(string)) if stringContent, ok := content.(string); ok {
return newOutOfLineContent(mediaType, stringContent)
}
return nil
default: default:
return nil return nil
} }