package atom import ( "errors" "fmt" "reflect" ) type InlineTextContent struct { *CommonAttributes Type string `xml:"type,attr,omitempty"` // Must be text or html Text string `xml:",chardata"` } // newInlineTextContent creates a new InlineTextContent. It returns a // *InlineTextContent and an error. func newInlineTextContent(mediaType string, content any) (*InlineTextContent, error) { if mediaType != "text" && mediaType != "html" && mediaType != "" { return nil, fmt.Errorf("media type %v incompatible with inline text content", mediaType) } if reflect.TypeOf(content).Kind() != reflect.String { return nil, fmt.Errorf("content type %T incompatible with inline text content", content) } return &InlineTextContent{Type: mediaType, Text: content.(string)}, nil } // isContent checks whether the InlineTextContent is a Content. It returns a // bool. func (i *InlineTextContent) isContent() bool { return true } // hasSRC checks whether the InlineTextContent has a SRC attribute. It returns // a bool. func (i *InlineTextContent) hasSRC() bool { return false } // getType returns the Type of the InlineTextContent as a string. func (i *InlineTextContent) getType() string { return i.Type } // Check checks the InlineTextContent for incompatibilities with RFC4287. It // returns an error. func (i *InlineTextContent) Check() error { if i.Type != "" && i.Type != "text" && i.Type != "html" { return errors.New("type attribute of inline text content must be text or html if not omitted") } return nil }