Documentation
¶
Overview ¶
Package contentencoder implements encoder functions for content types.
Index ¶
- 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 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 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.