Streamline type check in content constructs

This commit is contained in:
2024-10-17 18:12:56 +02:00
parent 040d7a6b7b
commit 17aa4b1a15
3 changed files with 13 additions and 13 deletions

View File

@@ -3,7 +3,6 @@ package atom
import (
"errors"
"fmt"
"reflect"
)
type InlineTextContent struct {
@@ -19,11 +18,12 @@ func newInlineTextContent(mediaType string, content any) (*InlineTextContent, er
return nil, fmt.Errorf("media type %v incompatible with inline text content", mediaType)
}
if reflect.TypeOf(content).Kind() != reflect.String {
text, ok := content.(string)
if !ok {
return nil, fmt.Errorf("content type %T incompatible with inline text content", content)
}
return &InlineTextContent{Type: mediaType, Text: content.(string)}, nil
return &InlineTextContent{Type: mediaType, Text: text}, nil
}
// isContent checks whether the InlineTextContent is a Content. It returns a