utils

package
v0.0.0-...-c714ef6 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombinedContext

func CombinedContext(signals ...interface{}) (context.Context, context.CancelFunc)

CombinedContext creates a context that finishes when any of the provided signals finish. A signal can be a `context.Context`, a `chan struct{}`, or a `time.Duration` (which is transformed into a `context.WithTimeout`).

func ContextFromChan

func ContextFromChan(chStop <-chan struct{}) (context.Context, context.CancelFunc)

ContextFromChan creates a context that finishes when the provided channel receives or is closed.

func DeepCopyJSValue

func DeepCopyJSValue(val interface{}) interface{}

@@TODO: everything about this is horrible

func DeviceIDFromX509Pubkey

func DeviceIDFromX509Pubkey(pubkey interface{}) string

func FilterEmptyStrings

func FilterEmptyStrings(s []string) []string

func GetValue

func GetValue(x interface{}, keypath []string) (interface{}, bool)

func GuessContentTypeFromFilename

func GuessContentTypeFromFilename(filename string) string

func IsLocalStateURI

func IsLocalStateURI(stateURI string) bool

func MakeSelfSignedX509Certificate

func MakeSelfSignedX509Certificate() (*tls.Certificate, error)

func ParseJWT

func ParseJWT(authHeader string, jwtSecret []byte) (jwt.MapClaims, bool, error)

func PrettyJSON

func PrettyJSON(x interface{}) string

func RandomBytes

func RandomBytes(length int) []byte

func RandomNumberString

func RandomNumberString() string

func RandomString

func RandomString(n int) string

func RespondJSON

func RespondJSON(resp http.ResponseWriter, data interface{})

func SniffContentType

func SniffContentType(filename string, data io.Reader) (string, error)

func TrimStringToLen

func TrimStringToLen(s string, length int) string

func UnmarshalHTTPRequest

func UnmarshalHTTPRequest(into interface{}, r *http.Request) error

func UnrestrictedCors

func UnrestrictedCors(handler http.Handler) http.Handler

Types

type ChanContext

type ChanContext chan struct{}

func (ChanContext) Deadline

func (ch ChanContext) Deadline() (deadline time.Time, ok bool)

func (ChanContext) Done

func (ch ChanContext) Done() <-chan struct{}

func (ChanContext) Err

func (ch ChanContext) Err() error

func (ChanContext) Value

func (ch ChanContext) Value(key interface{}) interface{}

type ExponentialBackoff

type ExponentialBackoff struct {
	Min time.Duration
	Max time.Duration
	// contains filtered or unexported fields
}

func (*ExponentialBackoff) Next

func (eb *ExponentialBackoff) Next() time.Duration

func (*ExponentialBackoff) Ready

func (eb *ExponentialBackoff) Ready() (ready bool, until time.Duration)

func (*ExponentialBackoff) Reset

func (eb *ExponentialBackoff) Reset()

func (*ExponentialBackoff) Wait

func (eb *ExponentialBackoff) Wait()

type ExponentialBackoffTicker

type ExponentialBackoffTicker struct {
	// contains filtered or unexported fields
}

func NewExponentialBackoffTicker

func NewExponentialBackoffTicker(min, max time.Duration) *ExponentialBackoffTicker

func (*ExponentialBackoffTicker) Close

func (t *ExponentialBackoffTicker) Close()

func (*ExponentialBackoffTicker) Notify

func (t *ExponentialBackoffTicker) Notify() <-chan time.Time

func (*ExponentialBackoffTicker) Reset

func (t *ExponentialBackoffTicker) Reset()

func (*ExponentialBackoffTicker) Start

func (t *ExponentialBackoffTicker) Start()

type HTTPClient

type HTTPClient struct {
	http.Client
	// contains filtered or unexported fields
}

func MakeHTTPClient

func MakeHTTPClient(requestTimeout, reapIdleConnsInterval time.Duration, cookieJar http.CookieJar, tlsCerts []tls.Certificate) *HTTPClient

func (HTTPClient) Close

func (c HTTPClient) Close()

type Mailbox

type Mailbox struct {
	// contains filtered or unexported fields
}

func NewMailbox

func NewMailbox(capacity uint64) *Mailbox

func (*Mailbox) Clear

func (m *Mailbox) Clear()

func (*Mailbox) Deliver

func (m *Mailbox) Deliver(x interface{})

func (*Mailbox) Notify

func (m *Mailbox) Notify() chan struct{}

func (*Mailbox) Retrieve

func (m *Mailbox) Retrieve() interface{}

func (*Mailbox) RetrieveAll

func (m *Mailbox) RetrieveAll() []interface{}

type StaticTicker

type StaticTicker struct {
	// contains filtered or unexported fields
}

func NewStaticTicker

func NewStaticTicker(interval time.Duration) StaticTicker

func (StaticTicker) Close

func (t StaticTicker) Close()

func (StaticTicker) Notify

func (t StaticTicker) Notify() <-chan time.Time

func (StaticTicker) Start

func (t StaticTicker) Start()

type Ticker

type Ticker interface {
	Start()
	Close()
	Notify() <-chan time.Time
}

type WaitGroupChan

type WaitGroupChan struct {
	// contains filtered or unexported fields
}

WaitGroupChan creates a channel that closes when the provided sync.WaitGroup is done.

func NewWaitGroupChan

func NewWaitGroupChan(ctx context.Context) *WaitGroupChan

func (*WaitGroupChan) Add

func (wg *WaitGroupChan) Add(i int)

func (*WaitGroupChan) Close

func (wg *WaitGroupChan) Close()

func (*WaitGroupChan) Done

func (wg *WaitGroupChan) Done()

func (*WaitGroupChan) Wait

func (wg *WaitGroupChan) Wait() <-chan struct{}

Jump to

Keyboard shortcuts

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