package atom import ( "encoding/xml" "fmt" "mime" ) type OutOfLineContent struct { XMLName xml.Name `xml:"content"` *CommonAttributes Type string `xml:"type,attr,omitempty"` // MediaType SRC string `xml:"src,attr"` // IRI } // newOutOfLineContent creates a new OutOfLineContent. It returns a // *OutOfLineContent. func newOutOfLineContent(mediaType, src string) *OutOfLineContent { mediaType, _, _ = mime.ParseMediaType(mediaType) return &OutOfLineContent{ CommonAttributes: NewCommonAttributes(), Type: mediaType, SRC: src, } } // isContent checks whether the OutOfLineContent is a Content. It returns a // bool. func (o *OutOfLineContent) isContent() bool { return true } // hasSRC checks whether the OutOfLineContent has a SRC attribute. It returns a // bool. func (o *OutOfLineContent) hasSRC() bool { return true } // getType returns the Type of the OutOfLineContent as a string. func (o *OutOfLineContent) getType() string { return o.Type } // Check checks the OutOfLineContent for incompatibilities with RFC4287. It // returns an error. func (o *OutOfLineContent) Check() error { mediaType := o.getType() if !isValidMediaType(mediaType) { return fmt.Errorf("type attribute of out of line content %v invalid media type", o) } if isCompositeMediaType(mediaType) { return fmt.Errorf("type attribute of out of line content %v must not be a composite type", o) } if o.SRC == "" { return fmt.Errorf("src attribute of out of line content %v empty", o) } return nil }