utils

package
v0.0.0-...-8e6f2e6 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Confirm

func Confirm(prompt string) bool

Confirm send the prompt and get result

func Do

func Do(domain, uri, method, accessToken string, post []byte) error

func DoBody

func DoBody(domain, uri, method, accessToken string, post []byte) ([]byte, error)

func DoBodyAddHeader

func DoBodyAddHeader(domain, uri, method, accessToken string, headers map[string]string, post []byte) ([]byte, error)

func EnvDefault

func EnvDefault(key, defVal string) string

func FileExist

func FileExist(path string) bool

func GetByteStream

func GetByteStream(s string) (bt []byte, err error)

GetByteStream is read file/url/stdin to []byte stream

func GetFile

func GetFile(s string) (bt []byte, err error)

func HasJSONPrefix

func HasJSONPrefix(buf []byte) bool

func IsEnvSet

func IsEnvSet(key string) bool

IsEnvSet returns true if an environment variable is set

func IsUrl

func IsUrl(u string) (url.URL, bool)

func JsonConvert

func JsonConvert(from interface{}, to interface{}) error

func ProcessError

func ProcessError(err error) error

func ReadByteFrom

func ReadByteFrom(in io.Reader) (bt []byte, err error)

func ReadStringFromFile

func ReadStringFromFile(s string) string

func Retry

func Retry(fn Func, retries int, sleep time.Duration, thundering bool) error

Do runs the passed function until the number of retries is reached. Whenever Func returns err it will sleep and Func will be executed again in a recursive fashion. The sleep value is slightly modified on every retry (exponential backoff) to prevent the thundering herd problem (https://en.wikipedia.org/wiki/Thundering_herd_problem). If no value is given to sleep it will defaults to 500ms.

Types

type Func

type Func func() error

Func is the function to be executed and eventually retried.

type HTTPFunc

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

HTTPFunc is the function to be executed and eventually retried. The only difference from Func is that it expects an *http.Response on the first returning argument.

Jump to

Keyboard shortcuts

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