simplehttpclient

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 13 Imported by: 0

README

Simple http client

This is a Golang module that provides:

  1. Easy file download without overwriting an already existing file if its md5sum matches the recently downloaded file. File downloading makes with temprorary name.
  2. Simple doing (GET/POST/PUT/...) http requests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckMD5sum

func CheckMD5sum(ctx context.Context, pathToFile, requiredMD5sum string) error

Calculates the md5sum of the specified file and compares it with the provided one.

func CopyByChunks

func CopyByChunks(ctx context.Context, src io.Reader, dst io.Writer, readBuffer int) (nBytes int64, err error)

Copying the content in parts from reader to specified writer, with Golang context.

func MD5sum

func MD5sum(ctx context.Context, file io.Reader) (string, error)

MD5Sum calculates md5 digest of the given content

Types

type Client

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

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new simple http client.

If [httpClient] is nil then will be used the default http client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, url string, requestBody io.Reader, headers map[string]string) (*http.Response, error)

Do makes an http request and returns its response

func (*Client) Download

func (c *Client) Download(ctx context.Context, url, dstLocalFilePath string, permissions fs.FileMode) error

Download uploads the contents of the request body to the specified local file

func (*Client) SetCorrectHttpStatus

func (c *Client) SetCorrectHttpStatus(httpStatus int) *Client

SetCorrectHttpStatus sets the HTTP status code that must be returned by http request, HTTP 200 by default

func (*Client) SetIgnoreCheckHttpStatus

func (c *Client) SetIgnoreCheckHttpStatus(b bool) *Client

SetIgnoreCheckHttpStatus set the value to [true] if you need to ignore HTTP status code check, default is [false]

func (*Client) SetRetries

func (c *Client) SetRetries(count int) *Client

SetRetries sets the number of retries, default is 5

func (*Client) SetRetriesTimeout

func (c *Client) SetRetriesTimeout(timeout time.Duration) *Client

SetRetriesTimeout sets timeout between retries, default is 1 second

Jump to

Keyboard shortcuts

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