request

package
v0.0.0-...-c54dfb2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 10 Imported by: 3 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSSEParse = errors.New("could not parse event stream")

ErrSSEParse is used when an error occurred while parsing the SSE stream.

Functions

func ReadJSON

func ReadJSON(r io.ReadCloser, data interface{}) error

ReadJSON reads the content of the specified ReadCloser and closes it.

func ReadSSE

func ReadSSE(r io.ReadCloser, ch chan *SSEEvent)

ReadSSE reads and parse a SSE source from a bufio.Reader into a channel of SSEEvent.

func Req

func Req(opts *Options) (*http.Response, error)

Req performs a request with the specified request options.

func WriteJSON

func WriteJSON(data interface{}) (io.Reader, error)

WriteJSON returns an io.Reader from which a JSON encoded data can be read.

Types

type Authorizer

type Authorizer interface {
	AuthHeader() string
	RealtimeToken() string
}

Authorizer is an interface to represent any element that can be used as a token bearer.

type BasicAuthorizer

type BasicAuthorizer struct {
	Username string
	Password string
}

BasicAuthorizer implements the HTTP basic auth for authorization.

func (*BasicAuthorizer) AuthHeader

func (b *BasicAuthorizer) AuthHeader() string

AuthHeader implemented the interface Authorizer.

func (*BasicAuthorizer) RealtimeToken

func (b *BasicAuthorizer) RealtimeToken() string

RealtimeToken implemented the interface Authorizer.

type BearerAuthorizer

type BearerAuthorizer struct {
	Token string
}

BearerAuthorizer implements a placeholder authorizer if the token is already known.

func (*BearerAuthorizer) AuthHeader

func (b *BearerAuthorizer) AuthHeader() string

AuthHeader implemented the interface Authorizer.

func (*BearerAuthorizer) RealtimeToken

func (b *BearerAuthorizer) RealtimeToken() string

RealtimeToken implemented the interface Authorizer.

type Error

type Error struct {
	Status string `json:"status"`
	Title  string `json:"title"`
	Detail string `json:"detail"`
}

Error is the typical JSON-API error returned by the API

func (*Error) Error

func (e *Error) Error() string

type Headers

type Headers map[string]string

Headers is a map of strings used to represent HTTP headers

type Options

type Options struct {
	Addr          string
	Domain        string
	Scheme        string
	Method        string
	Path          string
	Queries       url.Values
	Headers       Headers
	Body          io.Reader
	Authorizer    Authorizer
	ContentLength int64
	NoResponse    bool

	DisableSecure bool
	Client        *http.Client
	UserAgent     string
	ParseError    func(res *http.Response, b []byte) error
}

Options is a struct holding of the details of a request.

The NoResponse field can be used in case the call's response if not used. In such cases, the response body is automatically closed.

type SSEEvent

type SSEEvent struct {
	Name  string
	Data  []byte
	Error error
}

SSEEvent holds the data of a single SSE event.

Jump to

Keyboard shortcuts

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