http_client

package module
v0.0.0-...-a1cb6de Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

README

Http-client

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GobDecoder

func GobDecoder(reader io.Reader, res interface{}) error

func GobEncoder

func GobEncoder(payload interface{}) (io.Reader, error)

func JsonDecoder

func JsonDecoder(reader io.Reader, res interface{}) error

func JsonEncoder

func JsonEncoder(payload interface{}) (io.Reader, error)

Types

type DataDecoder

type DataDecoder func(reader io.Reader, res interface{}) error

type DataEncoder

type DataEncoder func(payload interface{}) (io.Reader, error)

type Err

type Err struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Meta    interface{} `json:"meta"`
}

func NewErr

func NewErr(code int, message string, meta interface{}) Err

func (Err) Error

func (e Err) Error() string

func (Err) Is

func (e Err) Is(target error) bool

func (Err) MarshalJSON

func (e Err) MarshalJSON() ([]byte, error)

func (Err) String

func (e Err) String() string

type HttpClient

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

func NewHttpClient

func NewHttpClient(params HttpClientParams) *HttpClient

func (*HttpClient) DoRequest

func (c *HttpClient) DoRequest(ctx context.Context,
	method string,
	url string,
	headers map[string]string,
	payload interface{},
	result interface{}) (*http.Response, error)

func (*HttpClient) DoRequestWithOptions

func (c *HttpClient) DoRequestWithOptions(options RequestOptions) (*http.Response, error)

func (*HttpClient) GetRequest

func (c *HttpClient) GetRequest(ctx context.Context,
	url string,
	headers map[string]string,
	result interface{}) (*http.Response, error)

func (*HttpClient) PostRequest

func (c *HttpClient) PostRequest(ctx context.Context,
	url string,
	headers map[string]string,
	payload interface{},
	result interface{}) (*http.Response, error)

func (*HttpClient) SetHeaders

func (c *HttpClient) SetHeaders(headers map[string]string)

type HttpClientParams

type HttpClientParams struct {
	BaseUrl               string
	ErrorHandler          func(closer io.Reader) error
	IsError               func(resp *http.Response) bool
	Headers               map[string]string
	Timeout               time.Duration
	RequestPayloadEncoder DataEncoder
	RequestPayloadDecoder DataDecoder
	MaxIdleConnsPerHost   int
	ContextRequestId      string
	HeaderKeyRequestID    string
	DebugMode             bool
}

type RequestOptions

type RequestOptions struct {
	Ctx                   context.Context
	Method                string
	Url                   string
	Headers               map[string]string
	Payload               interface{}
	Result                interface{}
	RequestPayloadEncoder DataEncoder
	RequestPayloadDecoder DataDecoder
	UrlParams             map[string]string
	AfterCallback         func(req *http.Request, resp *http.Response)
}

Jump to

Keyboard shortcuts

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