utils

package
v0.0.0-...-7553193 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode[T any](body io.Reader) (T, error)

func DecodeBytes

func DecodeBytes[T any](body []byte) (T, error)

func Encode

func Encode[T any](v T, w io.Writer) error

func ParseResponse

func ParseResponse[T any](response *http.Response) (T, error)

ParseResponse parses the HTTP response and returns the decoded value of type T. It checks http.Response.StatusCode, decodes and checks if the http.Response.Body decodes into types.ErrorResponse, and finally decodes into T if no errors are returned. ParseResponse also calls io.Closer.Close on the Body.

func StructToMultipartForm

func StructToMultipartForm(s any) (*bytes.Buffer, string, error)

StructToMultipartForm builds a multipart/form-data body from a struct. It returns the body buffer and the content type (with boundary).

func StructToMultipartPipe

func StructToMultipartPipe(s any) (io.ReadCloser, string, error)

StructToMultipartPipe builds a multipart/form-data body from a struct. It returns an io.ReadCloser and the content type (with boundary).

func StructToMultipartWriter

func StructToMultipartWriter(writer *multipart.Writer, s any) error

StructToMultipartWriter builds a multipart/form-data body from a struct. It writes to a multipart.Writer directly

func StructToUrlValues

func StructToUrlValues(s any) url.Values

StructToUrlValues converts a struct to url.Values.

Types

This section is empty.

Jump to

Keyboard shortcuts

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