package atomfeed import ( "errors" "fmt" "mime" "reflect" ) type OutOfLineContent struct { *CommonAttributes Type MediaType `xml:"type,attr,omitempty"` 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 !isValidURI(content.(URI)) { 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 } func (o *OutOfLineContent) getType() string { return string(o.Type) } func (o *OutOfLineContent) Check() error { mediaType := o.getType() if mediaType, _, err := mime.ParseMediaType(mediaType); err != nil { return fmt.Errorf("type attribute %v incompatible with out of line content", mediaType) } if isCompositeMediaType(mediaType) { return errors.New("type attribute of out of line content must not be a composite type") } if o.SRC == "" { return errors.New("src attribute of out of line content empty") } return nil }