httpclient

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

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 16 Imported by: 21

README

go-httpclient

Test

Go HTTP client.

GoDoc

Install

go get github.com/koofr/go-httpclient

Testing

go get -t
go test

Documentation

Index

Constants

View Source
const (
	EncodingJSON = "JSON"
	EncodingXML  = "XML"
	EncodingForm = "Form"
)

Variables

View Source
var DefaultClient = New()
View Source
var HttpClient = &http.Client{
	Transport: HttpTransport,
}
View Source
var HttpTransport = &http.Transport{
	DisableCompression: true,
	Proxy:              http.ProxyFromEnvironment,
}
View Source
var InsecureHttpClient = &http.Client{
	Transport: InsecureHttpTransport,
}
View Source
var InsecureHttpTransport = &http.Transport{
	TLSClientConfig:    InsecureTlsConfig,
	DisableCompression: true,
	Proxy:              http.ProxyFromEnvironment,
}
View Source
var InsecureTlsConfig = &tls.Config{
	InsecureSkipVerify: true,
}
View Source
var RateLimitTimeoutError = errors.New("HTTPClient rate limit timeout")
View Source
var XmlHeaderBytes []byte = []byte(xml.Header)

Functions

func EscapePath

func EscapePath(path string) string

func IsInvalidStatusCode

func IsInvalidStatusCode(err error, statusCode int) bool

Types

type Encoding

type Encoding string

type ErrorHandlerFunc

type ErrorHandlerFunc func(*http.Response, error) error

type HTTPClient

type HTTPClient struct {
	BaseURL   *url.URL
	Headers   http.Header
	Client    *http.Client
	PostHooks map[int]PostHookFunc
	// contains filtered or unexported fields
}

func Insecure

func Insecure() (httpClient *HTTPClient)

func New

func New() (httpClient *HTTPClient)

func (*HTTPClient) Request

func (c *HTTPClient) Request(req *RequestData) (response *http.Response, err error)

func (*HTTPClient) SetErrorHandler

func (c *HTTPClient) SetErrorHandler(handler ErrorHandlerFunc)

func (*HTTPClient) SetPostHook

func (c *HTTPClient) SetPostHook(onStatus int, hook PostHookFunc)

func (*HTTPClient) SetRateLimit

func (c *HTTPClient) SetRateLimit(limit int, timeout time.Duration)

func (*HTTPClient) UseInvalidStatusErrorPtr

func (c *HTTPClient) UseInvalidStatusErrorPtr()

type InvalidStatusError

type InvalidStatusError struct {
	Expected []int
	Got      int
	Headers  http.Header
	Content  string
}

func IsInvalidStatusError

func IsInvalidStatusError(err error) (invalidStatusError *InvalidStatusError, ok bool)

func (InvalidStatusError) Error

func (e InvalidStatusError) Error() string

type PostHookFunc

type PostHookFunc func(*http.Request, *http.Response) error

type RequestData

type RequestData struct {
	Context          context.Context
	Method           string
	Path             string
	Params           url.Values
	FullURL          string // client.BaseURL + Path or FullURL
	Headers          http.Header
	ReqReader        io.Reader
	ReqEncoding      Encoding
	ReqValue         interface{}
	ReqContentLength int64
	ExpectedStatus   []int
	IgnoreRedirects  bool
	RespEncoding     Encoding
	RespValue        interface{}
	RespConsume      bool
}

func (*RequestData) CanCopy

func (r *RequestData) CanCopy() bool

func (*RequestData) Copy

func (r *RequestData) Copy() (ok bool, nr *RequestData)

func (*RequestData) UploadFile

func (req *RequestData) UploadFile(fieldName string, fileName string, reader io.Reader) (err error)

func (*RequestData) UploadFileExtra

func (req *RequestData) UploadFileExtra(fieldName string, fileName string, reader io.Reader, extra map[string]string) (err error)

Jump to

Keyboard shortcuts

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