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 *