pipe

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func URL

func URL(base, endpoint string, params any) (string, error)

URL returns base, endpoint, and params encoded into a single url string with query paramters.

It uses net/url to parse base; expect mirrored error conditions. It uses path for endpoint normalization; expect the mirrored effects. It uses go-querystring for parameter values; expect mirrored error conditions.

Types

type Codec

type Codec interface {
	Marshal(any) ([]byte, error)
	Unmarshal([]byte, any) error
	ContentType() string
}

Codec is the interface implemented by any object that encodes and decodes to and from a specific content type.

type JSONCodec

type JSONCodec struct{}

JSONCodec implements a JSON codec.

func (JSONCodec) ContentType

func (JSONCodec) ContentType() string

func (JSONCodec) Marshal

func (JSONCodec) Marshal(v any) ([]byte, error)

func (JSONCodec) Unmarshal

func (JSONCodec) Unmarshal(data []byte, v any) error

type Option

type Option func(*Pipe)

Option is a function that sets a Pipe option.

func WithClient

func WithClient(client *http.Client) Option

WithClient sets Pipe to funnel through client.

func WithCodec

func WithCodec(codec Codec) Option

WithCodec sets Pipe to encode/decode the request/response body using codec.

type Pipe

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

Pipe funnels HTTP requests using an http.Client and a Codec.

func New

func New(opts ...Option) *Pipe

New returns a new Pipe configured with the given options. If no options are supplied, JSONCodec and http.DefaultClient are used.

func (*Pipe) Do

func (pipe *Pipe) Do(req *http.Request, out any) (*http.Response, error)

Do executes the given request with context. If the response status code indicates an error (>= 400), then an error is returned. Otherwise, the body is consumed and decoded into out if supplied.

func (*Pipe) NewRequestWithContext

func (pipe *Pipe) NewRequestWithContext(ctx context.Context, method, url string, body any) (*http.Request, error)

NewRequestWithContext returns a new request after successfuly encoding body with codec and setting the content-type and accept header fields.

type XMLCodec

type XMLCodec struct{}

XMLCodec implements an XML codec.

func (XMLCodec) ContentType

func (XMLCodec) ContentType() string

func (XMLCodec) Marshal

func (XMLCodec) Marshal(v any) ([]byte, error)

func (XMLCodec) Unmarshal

func (XMLCodec) Unmarshal(data []byte, v any) error

Jump to

Keyboard shortcuts

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