Documentation
¶
Overview ¶
Package contenttype implement encoders and decoders for data by content types.
Index ¶
- func Decode(contentType string, rawBody io.Reader) (any, error)
- func DecodeXML(r io.Reader) (any, error)
- func Encode(contentType string, body any) ([]byte, error)
- func EncodeBinary(body any) ([]byte, error)
- func EncodeFormURLEncoded(value any, media *highv3.MediaType) (string, error)
- func EncodeMultipartForm(bodyData any, headers http.Header, media *highv3.MediaType) ([]byte, string, error)
- func EncodeText(body any) ([]byte, error)
- func EncodeXML(value any) ([]byte, error)
- func Write(writer io.Writer, contentType string, body any) (int, error)
- func WriteBinary(writer io.Writer, body any) (int, error)
- func WriteText(writer io.Writer, body any) (int, error)
- func WriteXML(writer io.Writer, value any) (int, error)
- type DataURI
- type DataURIEncoding
- type MultipartWriter
- func (w *MultipartWriter) WriteBinary(name string, value []byte, contentType string, headers http.Header) error
- func (w *MultipartWriter) WriteDataURI(name string, value any, contentType string, headers http.Header) error
- func (w *MultipartWriter) WriteField(fieldName, value string, headers http.Header) error
- func (w *MultipartWriter) WriteJSON(fieldName string, value any, headers http.Header) error
- func (w *MultipartWriter) WriteXML(fieldName string, value any, headers http.Header) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeBinary ¶
EncodeBinary encodes the arbitrary value to bytes for binary content type.
func EncodeFormURLEncoded ¶
EncodeFormURLEncoded encodes the arbitrary value to application/x-www-form-urlencoded content type.
func EncodeMultipartForm ¶
func EncodeMultipartForm( bodyData any, headers http.Header, media *highv3.MediaType, ) ([]byte, string, error)
EncodeMultipartForm encodes the arbitrary value to multipart/form-data content type.
func EncodeText ¶
EncodeText encodes the arbitrary value to text for text/xxx content type.
func WriteBinary ¶
WriteBinary encodes the arbitrary value to bytes for binary content type and writes it into the write stream.
Types ¶
type DataURI ¶
DataURI represents the Data URI scheme
func DecodeDataURI ¶
DecodeDataURI decodes data URI scheme data:[<media type>][;<key>=<value>][;<extension>],<data>
type DataURIEncoding ¶
type DataURIEncoding uint8
DataURIEncoding represents a encoding num for the data URI.
const ( // DataUriASCII represents the ascii encoding for the data URI. DataUriASCII DataURIEncoding = iota // DataURIBase64 represents the base64 encoding enum for the data URI. DataURIBase64 )
type MultipartWriter ¶
MultipartWriter extends multipart.Writer with helpers.
func NewMultipartWriter ¶
func NewMultipartWriter(w io.Writer) *MultipartWriter
NewMultipartWriter creates a MultipartWriter instance.
func (*MultipartWriter) WriteBinary ¶
func (w *MultipartWriter) WriteBinary( name string, value []byte, contentType string, headers http.Header, ) error
WriteBinary writes a binary file to the multipart form.
func (*MultipartWriter) WriteDataURI ¶
func (w *MultipartWriter) WriteDataURI( name string, value any, contentType string, headers http.Header, ) error
WriteDataURI write a file from data URI string.
func (*MultipartWriter) WriteField ¶
func (w *MultipartWriter) WriteField(fieldName, value string, headers http.Header) error
WriteField calls CreateFormField and then writes the given value.