request

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryParam  = "queries"
	HeaderParam = "headers"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Get(targetURL string, opts SendOptions) (*Response, error)
	Put(targetURL string, opts SendOptions, body []byte) (*Response, error)
	Post(targetURL string, opts SendOptions, body []byte) (*Response, error)
	Patch(targetURL string, opts SendOptions, body []byte) (*Response, error)
	Delete(targetURL string, opts SendOptions, body []byte) (*Response, error)
	Send(method, path string, opts SendOptions, body []byte) (*Response, error)
	GetStandardClient() *http.Client
}

Client provided for mock

func NewClient

func NewClient(optsClient ...OptionClient) Client

NewClient init http client

func NewClientWithDebug

func NewClientWithDebug(debugEnable bool, optsClient ...OptionClient) Client

NewClientWithDebug init http client with debug config

type OptionClient

type OptionClient func(*retryablehttp.Client)

OptionClient represents an option for the http client

func WithRetryMax

func WithRetryMax(retryMax int) OptionClient

WithRetryMax sets max retry of the client options

func WithTimeout

func WithTimeout(timeout time.Duration) OptionClient

WithTimeout sets timeout of the client options

type Response

type Response struct {
	Body       []byte
	Header     http.Header
	StatusCode int
}

Response struct

type SendOptions

type SendOptions map[string]map[string]interface{}

SendOptions for attached data through a request Example should be add query params (http://abcd.com?user=ec&limit=5) or header

SendOptions {
 "queries": map[string]interface{}{
    "user": "ec",
    "limit": "5",
 },
	"headers": map[string]interface{}{
    "xxx":         	"abc",
    "Content-Type":  "application/json",
	},
}

func (SendOptions) SetContentType

func (opt SendOptions) SetContentType(t string) SendOptions

SetContentType sets a content type of the request

func (SendOptions) SetQueryParam

func (opt SendOptions) SetQueryParam(params map[string]interface{}) SendOptions

SetContentType sets query params of the request

Jump to

Keyboard shortcuts

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