util

package
v0.0.0-...-a514ca2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 10 Imported by: 11

Documentation

Overview

Package util is the dumping ground for helper functions without a good home.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgListToMap

func ArgListToMap(args ...interface{}) map[string]interface{}

ArgListToMap converts an argument list to a map, e.g. ("key", value, "key2", value2) => {"key": value, "key2", value2}

func CheckHTTPResponse

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

CheckHTTPResponse does some basic error handling and reads the response body into a byte array

func SignalContext

func SignalContext(ctx context.Context, delay time.Duration, sigs ...os.Signal) context.Context

SignalContext will cancel the context when any of the given signals is received.

Types

type IdleTimeout

type IdleTimeout interface {
	Done() <-chan time.Time
	Start()
	Stop()
}

IdleTimeout provides a helper for managing the Pool's idle timeout. Start() and Stop() are used to control the timer, and Done() is used to detect when the timeout has been reached.

in := make(chan int) requestInput(in) t := IdleTimeoutAfter(time.Second * 10)

for {
  select {
  case <-t.Done():
    // ... code to respond to timeout
  case <-in:
    // Reset the timeout.
    t.Start()
  }
}

func NewIdleTimeout

func NewIdleTimeout(d time.Duration) IdleTimeout

NewIdleTimeout returns an IdleTimeout instance for the given duration.

func NoIdleTimeout

func NoIdleTimeout() IdleTimeout

NoIdleTimeout creates an IdleTimeout that never times out.

type MultiError

type MultiError []error

MultiError helps collect multiple errors and implements Go's "error" interface.

func (MultiError) Error

func (m MultiError) Error() string

Error returns all the error strings joined by a newline.

func (MultiError) IsNil

func (m MultiError) IsNil() bool

IsNil returns true if all errors in the slice are nil.

func (MultiError) ToError

func (m MultiError) ToError() error

ToError returns an error interface.

type Retrier

type Retrier struct {
	InitialInterval     time.Duration
	MaxInterval         time.Duration
	Multiplier          float64
	RandomizationFactor float64
	MaxElapsedTime      time.Duration
	MaxTries            int
	ShouldRetry         func(err error) bool
	Notify              func(err error, d time.Duration)
	// contains filtered or unexported fields
}

Retrier is a wrapper around "github.com/cenkalti/backoff".ExponentialBackOff

func NewRetrier

func NewRetrier() *Retrier

NewRetrier creates a new Retrier instance using default values.

func (*Retrier) Retry

func (r *Retrier) Retry(ctx context.Context, f func() error) error

Retry the function f until it does not return error or BackOff stops.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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