httpclient

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: Apache-2.0 Imports: 13 Imported by: 16

README

Http Client

As every one knows go default http client can not be used in production, you must implement your own http client.

httpclient is a production ready client.

	options := &httpclient.URLClientOption{
		TLSConfig:  opt.TLSConfig,
		Compressed: opt.Compressed,
	}
	c, err = httpclient.New(options)
	if err != nil {
		return err
	}
	resp, err := uc.Do("GET", "https://fakeURL", nil, nil)

Debug Mode

export HTTP_DEBUG=1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Compressed:            true,
	HandshakeTimeout:      30 * time.Second,
	ResponseHeaderTimeout: 60 * time.Second,
	RequestTimeout:        60 * time.Second,
	ConnsPerHost:          5,
	TLSVersion:            tls.VersionTLS13,
}

DefaultOptions is a struct object which has default client option

View Source
var SignRequest func(*http.Request) error

SignRequest sign a http request so that it can talk to API server this is global implementation, if you do not set SignRequest in Options client will use this function

Functions

func NewGZipBodyReader

func NewGZipBodyReader(body io.ReadCloser) (io.ReadCloser, error)

Types

type Options

type Options struct {
	TLSVersion            int
	TLSConfig             *tls.Config
	Compressed            bool
	HandshakeTimeout      time.Duration
	ResponseHeaderTimeout time.Duration
	RequestTimeout        time.Duration
	ConnsPerHost          int
	SignRequest           func(*http.Request) error
}

Options is a struct which provides options for client

type Requests

type Requests struct {
	*http.Client
	// contains filtered or unexported fields
}

Requests is a restful client

func New

func New(o *Options) (client *Requests, err error)

New is a function which which sets client option

func (*Requests) Delete

func (r *Requests) Delete(ctx context.Context, url string, headers http.Header) (resp *http.Response, err error)

func (*Requests) Do

func (r *Requests) Do(ctx context.Context, method string, url string, headers http.Header, body []byte) (resp *http.Response, err error)

func (*Requests) Get

func (r *Requests) Get(ctx context.Context, url string, headers http.Header) (resp *http.Response, err error)

func (*Requests) Post

func (r *Requests) Post(ctx context.Context, url string, headers http.Header, body []byte) (resp *http.Response, err error)

func (*Requests) Put

func (r *Requests) Put(ctx context.Context, url string, headers http.Header, body []byte) (resp *http.Response, err error)

Jump to

Keyboard shortcuts

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