utils

package
v0.23.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationFromEnvOrDefault

func DurationFromEnvOrDefault(
	envVarName string,
	defaultValue string,
	getEnv GetEnvFunc,
) (time.Duration, error)

DurationFromEnvOrDefault extracts the value of the given environment variable, or the default value if the environment variable is not defined, and returns it as a time.Duration object

func IntFromEnvOrDefault

func IntFromEnvOrDefault(
	envVarName string,
	defaultValue string,
	getEnv GetEnvFunc,
) (int, error)

IntFromEnvOrDefault extracts the value of the given environment variable, or the default value if the environment variable is not defined, and returns it as an int object

func NewLimitedBackOff

func NewLimitedBackOff(interval time.Duration, retryLimit int) *limitedBackOff

func NewResponseError added in v0.19.1

func NewResponseError(resp *http.Response) error

NewResponseError creates a new instance of Error

func ReadResponseBody added in v0.19.1

func ReadResponseBody(resp *http.Response) ([]byte, error)

ReadResponseBody returns the response body

func ValidateResponse added in v0.19.1

func ValidateResponse(resp *http.Response) error

validateResponse checks the HTTP status of the response. If it's less than 300, it returns the response body as a byte array. Otherwise it returns a NewResponseError.

func VerifyFileExists added in v0.19.0

func VerifyFileExists(path string) error

VerifyFileExists verifies that a file exists at a given path and is a regular file.

func WaitForFile

func WaitForFile(
	path string,
	retryCountLimit int,
) error

WaitForFile waits for retryCountLimit seconds to see if the file exists in the given path. If it's not there by the end of the retry count limit, it returns an error.

Types

type Error added in v0.19.1

type Error struct {
	Code    int
	Message string
	Details *ErrorDetails `json:"error"`
}

Error includes the error info for response errors

func (*Error) Error added in v0.19.1

func (responseErr *Error) Error() string

Error returns the error message

type ErrorDetails added in v0.19.1

type ErrorDetails struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ErrorDetails includes JSON data on Errors

type GetEnvFunc

type GetEnvFunc func(envVarName string) string

GetEnvFunc is a function that returns a value for an environment variable

Jump to

Keyboard shortcuts

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