Add newOutOfLineContent
This commit is contained in:
parent
ea79900bf3
commit
9df834d927
@ -1,6 +1,12 @@
|
||||
package atomfeed
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime"
|
||||
"net/url"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type OutOfLineContent struct {
|
||||
*CommonAttributes
|
||||
@ -8,6 +14,22 @@ type OutOfLineContent struct {
|
||||
SRC URI `xml:"src,attr"`
|
||||
}
|
||||
|
||||
func newOutOfLineContent(mediaType string, content any) (*OutOfLineContent, error) {
|
||||
if mediaType, _, err := mime.ParseMediaType(mediaType); err != nil {
|
||||
return nil, fmt.Errorf("media type %v incompatible with out of line content", mediaType)
|
||||
}
|
||||
|
||||
if reflect.TypeOf(content).Kind() != reflect.String {
|
||||
return nil, fmt.Errorf("content type %T incompatible with out of line content", content)
|
||||
}
|
||||
|
||||
if _, err := url.ParseRequestURI(content.(string)); err != nil {
|
||||
return nil, errors.New("content not a valid uri")
|
||||
}
|
||||
|
||||
return &OutOfLineContent{Type: MediaType(mediaType), SRC: content.(URI)}, nil
|
||||
}
|
||||
|
||||
func (o *OutOfLineContent) isContent() bool { return true }
|
||||
|
||||
func (o *OutOfLineContent) hasSRC() bool { return true }
|
||||
|
Loading…
x
Reference in New Issue
Block a user