client

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIConfig

type APIConfig struct {
	Host    string
	Path    string
	Query   map[string]string // Query use for http get request for set query params example.com/x?q1=v1&q2=v2
	Headers map[string]string // Headers set http header request
}

APIConfig use for provider standard external api path address

type Client

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

func (*Client) Get

func (c *Client) Get(ctx context.Context, apiConfig *APIConfig) (*Response, error)

Get do get request and return response

func (*Client) GetClient

func (c *Client) GetClient() *http.Client

func (*Client) GetValidator

func (c *Client) GetValidator() *validator.Validate

func (*Client) Post

func (c *Client) Post(ctx context.Context, apiConfig *APIConfig, apiRequest any) (*Response, error)

Post do post request and return response

type Method

type Method int

Method is http method for request

const (
	POST Method = iota + 1
	GET
	PUT
	PATCH
	DELETE
)

func (Method) String

func (i Method) String() string

type Option

type Option func(client *Client)

func WithCustomClient

func WithCustomClient(client *http.Client) Option

WithCustomClient use custom http httpClient instead default httpClient

func WithRateLimit

func WithRateLimit(every time.Duration, requestPerTime int) Option

WithRateLimit make rate limit for example every time 5 * time.Second for 50 request

type Response

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

func (*Response) GetHttpResponse

func (r *Response) GetHttpResponse() *http.Response

GetHttpResponse return http response

func (*Response) GetJSON

func (r *Response) GetJSON(response any) error

GetJSON decode response body to your response

type Transporter

type Transporter interface {
	GetClient() *http.Client
	GetValidator() *validator.Validate
	Get(ctx context.Context, apiConfig *APIConfig) (*Response, error)
	Post(ctx context.Context, apiConfig *APIConfig, apiRequest any) (*Response, error)
}

func New

func New(opts ...Option) Transporter

New create httpClient constructor

Jump to

Keyboard shortcuts

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