Streamline type check in content constructs
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user