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

@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"mime"
"reflect"
)
type OutOfLineContent struct {
@@ -20,15 +19,16 @@ func newOutOfLineContent(mediaType string, content any) (*OutOfLineContent, erro
return nil, fmt.Errorf("media type %v incompatible with out of line content", mediaType)
}
if reflect.TypeOf(content).Kind() != reflect.String {
iri, ok := content.(IRI)
if !ok {
return nil, fmt.Errorf("content type %T incompatible with out of line content", content)
}
if !isValidIRI(content.(IRI)) {
if !isValidIRI(iri) {
return nil, errors.New("content not a valid uri")
}
return &OutOfLineContent{Type: MediaType(mediaType), SRC: content.(IRI)}, nil
return &OutOfLineContent{Type: MediaType(mediaType), SRC: iri}, nil
}
// isContent checks whether the OutOfLineContent is a Content. It returns a