contentencoder

package
v0.0.0-...-3a583f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package contentencoder implements encoder functions for content types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(contentType string, body any) ([]byte, error)

Encode encodes the data by content type.

func EncodeBinary

func EncodeBinary(body any) ([]byte, error)

EncodeBinary encodes the arbitrary value to bytes for binary content type.

func EncodeFormURLEncoded

func EncodeFormURLEncoded(value any, media *highv3.MediaType) (string, error)

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

func EncodeText(body any) ([]byte, error)

EncodeText encodes the arbitrary value to text for text/xxx content type.

func EncodeXML

func EncodeXML(value any) ([]byte, error)

EncodeXML encodes the arbitrary body to XML bytes.

func Write

func Write(writer io.Writer, contentType string, body any) (int, error)

Write encodes the data by content type and writes it to the stream.

func WriteBinary

func WriteBinary(writer io.Writer, body any) (int, error)

WriteBinary encodes the arbitrary value to bytes for binary content type and writes it into the write stream.

func WriteText

func WriteText(writer io.Writer, body any) (int, error)

WriteText encodes the arbitrary value to text for text/xxx content type and write it into the stream.

func WriteXML

func WriteXML(writer io.Writer, value any) (int, error)

WriteXML encodes the arbitrary body to XML and write to a writer.

Types

type MultipartWriter

type MultipartWriter struct {
	*multipart.Writer
}

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.

func (*MultipartWriter) WriteJSON

func (w *MultipartWriter) WriteJSON(fieldName string, value any, headers http.Header) error

WriteJSON calls CreateFormField and then writes the given value with json encoding.

func (*MultipartWriter) WriteXML

func (w *MultipartWriter) WriteXML(fieldName string, value any, headers http.Header) error

WriteXML calls CreateFormField and then writes the given value with XML encoding.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL