util

package
v0.0.0-...-c2b5c71 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package util has code that does not fit anywhere else

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(s []string, e string) bool

Contains checks if a string is in a slice

func EnsureViperSub

func EnsureViperSub(viper *viper.Viper, key string) *viper.Viper

EnsureViperSub will return a viper sub if available or create one

func Log

func Log() *zap.SugaredLogger

Log returns the SuggardLoggar that can be used accross integrations

func NewHTTPTestServer

func NewHTTPTestServer(handlerFunc func(w http.ResponseWriter, r *http.Request)) *httptest.Server

NewHTTPTestServer returns a new httptest.Server with a given handlerFunc

func NoopLog

func NoopLog() *zap.SugaredLogger

NoopLog returns a no-op logger, that can be used to supress logging

func ReadKeyFile

func ReadKeyFile(t *testing.T, fileName string) []byte

ReadKeyFile reads a key file and returns the content

func Retry

func Retry(attempts int, sleep time.Duration, callbackFunc func() error) error

Retry attempts to execute the given callback function a certain number of times, with a delay between each attempt using a simple exponential backoff algorithm that uses a slight jitter to ensure that retries aren't clustered.

If the callback function returns an error, Retry will sleep for a certain duration before attempting to call the callback function again.

Retry will repeat this process until the callback function succeeds or until the maximum number of attempts is reached.

If the maximum number of attempts is reached and the callback function still fails, it returns the last error returned by the callback function.

func RetryStop

func RetryStop(err error) error

RetryStop wraps the given error in a private retryError type and returns it to signal that a retry loop should stop attempting the operation that produced the given error.

func StrPointer

func StrPointer(s string) *string

StrPointer returns a pointer to a string

Types

type AuthedTransport

type AuthedTransport struct {
	Key     string
	Wrapped http.RoundTripper
}

AuthedTransport is a http.RoundTripper that adds an Authorization header

func (*AuthedTransport) RoundTrip

func (t *AuthedTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper and sets Authorization header

Jump to

Keyboard shortcuts

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