client

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 14 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateURI

func GenerateURI(uri string, queryParams map[string]string) string

func GetResponseHeaders

func GetResponseHeaders(resp *fasthttp.Response) map[string]string

func SetHeaders

func SetHeaders(req *fasthttp.Request, headers map[string]string)

func SetHeadersInRequest

func SetHeadersInRequest(headers interface{}, req *fasthttp.Request) error

func SetQueryParamsInURI

func SetQueryParamsInURI(queryParams interface{}, uri string) (string, error)

SetQueryParamsInURI sets query parameters in the URI returns uri string without any error

func SetRequestBody

func SetRequestBody(body interface{}, req *fasthttp.Request) error

sets body if present and returns nil as error. Function will also return nil if body == nil

Types

type ClientInterface

type ClientInterface interface {
	Do(uri string, method string, queryParams any, headers any, body any) (*Response, error)
}

type ConcurrentResponse

type ConcurrentResponse struct {
	Response *Response `json:"response" yaml:"response"`
	Error    error     `json:"error" yaml:"error"`
}

func MakeConcurrentRequests

func MakeConcurrentRequests(requests []*Request, client ClientInterface) []*ConcurrentResponse

func NewConcurrentResponse

func NewConcurrentResponse(response *Response, err error) *ConcurrentResponse

type FHClient

type FHClient struct {
	Client *fasthttp.Client
}

func NewFHClient

func NewFHClient(fasthttp *fasthttp.Client) *FHClient

func (*FHClient) Do

func (c *FHClient) Do(uri string, method string, queryParams any, headers any, reqBody any) (*Response, error)

type RateLimitedClient

type RateLimitedClient struct {
	Requests    int
	PerSeconds  int
	RateLimited *rate.Limiter
	FHClient    *FHClient
}

func NewRateLimitedClient

func NewRateLimitedClient(requests int, perSeconds int, fasthttp *fasthttp.Client) *RateLimitedClient

func (*RateLimitedClient) Do

func (rc *RateLimitedClient) Do(uri string, method string, queryParams any, headers any, reqBody any) (*Response, error)

type Request

type Request struct {
	Uri         string      `json:"uri" yaml:"uri"`
	Method      string      `json:"method" yaml:"method"`
	QueryParams interface{} `json:"query_params" yaml:"query_params"`
	Headers     interface{} `json:"headers" yaml:"headers"`
	Body        interface{} `json:"body" yaml:"body"`
}

func NewRequest

func NewRequest(uri string, method string, queryParams any, headers any, body any) *Request

type Response

type Response struct {
	StatusCode  int               `json:"status_code" yaml:"status_code"`
	Headers     map[string]string `json:"headers" yaml:"headers"`
	Body        []byte            `json:"body" yaml:"body"`
	CurlCommand string            `json:"curl_command" yaml:"curl_command"`
	TimeElapsed time.Duration     `json:"time_elapsed" yaml:"time_elapsed"`
}

func Connect

func Connect(client ClientInterface, uri string, queryParams any, headers any) (*Response, error)

func Delete

func Delete(client ClientInterface, uri string, queryParams any, headers any, body any) (*Response, error)

func Get

func Get(client ClientInterface, uri string, queryParams any, headers any) (*Response, error)
func Head(client ClientInterface, uri string, queryParams any, headers any) (*Response, error)

func NewResponse

func NewResponse(statusCode int, headers map[string]string, body []byte, curlCmd string, duration time.Duration) *Response

func Options

func Options(client ClientInterface, uri string, queryParams any, headers any) (*Response, error)

func Patch

func Patch(client ClientInterface, uri string, queryParams any, headers any, body any) (*Response, error)

func Post

func Post(client ClientInterface, uri string, queryParams any, headers any, body any) (*Response, error)

func Put

func Put(client ClientInterface, uri string, queryParams any, headers any, body any) (*Response, error)

func Trace

func Trace(client ClientInterface, uri string, queryParams any, headers any) (*Response, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳