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