utils

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(doFunc func() error, opts ...RetryOption) error

Retry retries the func until it returns no error or reaches attempts limit or timed out, either one is earlier

func TailN added in v1.0.7

func TailN(fname string, n int) (lines []string, err error)

TailN try get the latest n line of the file.

Types

type HTTPClient

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

HTTPClient is a wrap of http.Client

func NewHTTPClient

func NewHTTPClient(timeout time.Duration, tlsConfig *tls.Config) *HTTPClient

NewHTTPClient returns a new HTTP client with timeout and HTTPS support

func (*HTTPClient) Delete

func (c *HTTPClient) Delete(url string, body io.Reader) ([]byte, int, error)

Delete send a DELETE request to the url and returns the response and status code.

func (*HTTPClient) Get

func (c *HTTPClient) Get(url string) ([]byte, error)

Get fetch an URL with GET method and returns the response

func (*HTTPClient) Post

func (c *HTTPClient) Post(url string, body io.Reader) ([]byte, error)

Post send a POST request to the url and returns the response

type RetryOption

type RetryOption struct {
	Attempts int64
	Delay    time.Duration
	Timeout  time.Duration
}

RetryOption is options for Retry()

Jump to

Keyboard shortcuts

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