httputils

package
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HttpDelete

func HttpDelete(httpClient IHttpClient, fullURL string, headers map[string]string) (*http.Response, error)

func HttpDeleteWithContext added in v0.0.13

func HttpDeleteWithContext(ctx context.Context, httpClient IHttpClient, fullURL string, headers map[string]string) (*http.Response, error)

func HttpGet

func HttpGet(httpClient IHttpClient, fullURL string, headers map[string]string) (*http.Response, error)

func HttpGetWithContext added in v0.0.13

func HttpGetWithContext(ctx context.Context, httpClient IHttpClient, fullURL string, headers map[string]string) (*http.Response, error)

func HttpHead added in v0.0.12

func HttpHead(httpClient IHttpClient, fullURL string, headers map[string]string) (*http.Response, error)

func HttpHeadWithContext added in v0.0.13

func HttpHeadWithContext(ctx context.Context, httpClient IHttpClient, fullURL string, headers map[string]string) (*http.Response, error)

func HttpPost

func HttpPost(httpClient IHttpClient, fullURL string, headers map[string]string, body []byte) (*http.Response, error)

func HttpPostWithContext added in v0.0.13

func HttpPostWithContext(ctx context.Context, httpClient IHttpClient, fullURL string, headers map[string]string, body []byte, maxElapsedTime time.Duration, shouldRetry func(resp *http.Response) bool) (*http.Response, error)

func HttpPostWithRetry added in v0.0.57

func HttpPostWithRetry(httpClient IHttpClient, fullURL string, headers map[string]string, body []byte, maxElapsedTime time.Duration) (*http.Response, error)

func HttpRespToString

func HttpRespToString(resp *http.Response) (string, error)

HttpRespToString parses the body as string and checks the HTTP status code, it closes the body reader at the end

func JSONDecoder

func JSONDecoder(origin string) *json.Decoder

JSONDecoder returns JSON decoder for given string

func JSONSize

func JSONSize(i interface{}) int

JSONSize returns the size in bytes of the json encoding of i

func Split2Chunks added in v0.0.14

func Split2Chunks[T any](maxNumOfChunks int, slice []T) [][]T

func SplitSlice2Chunks

func SplitSlice2Chunks[T any](slice []T, maxSize int, channelBuffer int) (chunksChannel <-chan []T, sliceSize int)

SplitSlice2Chunks - *recursively* splits a slice to chunks of sub slices that do not exceed max bytes size Returns a channels for receiving []T chunks and the original len of []T If []T is empty the function will return a closed chunks channel Chunks might be bigger than max size if the slice contains element(s) that are bigger than the max size this split algorithm fits for slices with elements that share more or less the same size per element uses optimistic average size splitting to enhance performance and reduce the use of json encoding for size calculations chunks channel will be closed after splitting is done

Types

type IHttpClient added in v0.0.11

type IHttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type ShouldNotRetryFunc added in v0.0.57

type ShouldNotRetryFunc func(resp *http.Response) bool

Jump to

Keyboard shortcuts

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