request

package
v0.0.0-...-d5ce8da Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHTTPClient = func() *http.Client {
	return &http.Client{
		Transport: DefaultHTTPTransport,
		Timeout:   90 * time.Second,
	}
}()
View Source
var DefaultHTTPTransport = func() *http.Transport {
	transport := http.DefaultTransport.(*http.Transport).Clone()
	transport.DisableKeepAlives = true
	return transport
}()

Functions

This section is empty.

Types

type APIResponse

type APIResponse[T interface{}] struct {
	Header     http.Header
	StatusCode int
	Data       T
}

func NewAPIResponse

func NewAPIResponse[T interface{}](res *http.Response, data T) APIResponse[T]

type Context

type Context interface {
	GetAPIKey(fallbackAPIKey string) string
	GetContext() context.Context
	PrepareHeader(header *http.Header)
	PrepareQuery(query *url.Values)
	PrepareBody(method string, query *url.Values) (body io.Reader, contentType string, err error)
	NewRequest(baseURL *url.URL, method, path string, header func(header *http.Header, params Context), query func(query *url.Values, params Context)) (req *http.Request, err error)
}

type Ctx

type Ctx struct {
	APIKey  string          `json:"-"`
	Context context.Context `json:"-"`
	Form    *url.Values     `json:"-"`
	JSON    any             `json:"-"`
	Headers *http.Header    `json:"-"`
	Query   *url.Values     `json:"-"`
}

func (Ctx) GetAPIKey

func (ctx Ctx) GetAPIKey(fallbackAPIKey string) string

func (Ctx) GetContext

func (ctx Ctx) GetContext() context.Context

func (Ctx) NewRequest

func (ctx Ctx) NewRequest(baseURL *url.URL, method, path string, header func(header *http.Header, params Context), query func(query *url.Values, params Context)) (req *http.Request, err error)

func (Ctx) PrepareBody

func (ctx Ctx) PrepareBody(method string, query *url.Values) (body io.Reader, contentType string, err error)

func (Ctx) PrepareHeader

func (ctx Ctx) PrepareHeader(header *http.Header)

func (Ctx) PrepareQuery

func (ctx Ctx) PrepareQuery(query *url.Values)

Jump to

Keyboard shortcuts

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