bodyprovider

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package bodyprovider implements the concrete BodyProvider variants used by the greq client (reader, JSON, form, multipart). The greq.BodyProvider interface is structurally satisfied by every type in this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Form

type Form struct {
	// contains filtered or unexported fields
}

Form encodes a url tagged struct value (or string/url.Values/map[string][]string) as form body.

func NewForm

func NewForm(payload any) Form

NewForm returns a Form provider.

func (Form) Body

func (p Form) Body() (io.Reader, error)

Body encodes the payload into a form-urlencoded reader.

func (Form) ContentType

func (p Form) ContentType() string

ContentType returns application/x-www-form-urlencoded.

type JSON

type JSON struct {
	// contains filtered or unexported fields
}

JSON encodes a JSON tagged struct value as request body.

func NewJSON

func NewJSON(payload any) JSON

NewJSON returns a JSON provider.

func (JSON) Body

func (p JSON) Body() (io.Reader, error)

Body marshals the payload into a JSON reader.

func (JSON) ContentType

func (p JSON) ContentType() string

ContentType returns application/json.

type Multipart

type Multipart struct {
	// contains filtered or unexported fields
}

Multipart builds a multipart/form-data body from files and fields. Uses a pointer receiver because Body() lazily materializes the buffer.

IMPORTANT: ContentType() returns "" until Body() has been called at least once (because the multipart boundary is generated during build()). Callers that need both the body and the Content-Type header MUST call Body() first. The greq client does this already in NewRequestWithOptions.

func NewMultipart

func NewMultipart(files, fields map[string]string) *Multipart

NewMultipart returns a Multipart provider. Either map may be nil.

func (*Multipart) Body

func (p *Multipart) Body() (io.Reader, error)

Body lazily builds the multipart body on first call.

func (*Multipart) ContentType

func (p *Multipart) ContentType() string

ContentType returns the multipart Content-Type including the boundary. Returns empty string until Body() has been called at least once.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader wraps an io.Reader and exposes it as a body without a Content-Type.

func NewReader

func NewReader(r io.Reader) Reader

NewReader returns a Reader provider.

func (Reader) Body

func (p Reader) Body() (io.Reader, error)

Body returns the underlying reader.

func (Reader) ContentType

func (p Reader) ContentType() string

ContentType returns the Content-Type — empty for raw reader bodies.

Jump to

Keyboard shortcuts

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