common

package
v0.3.750 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: Apache-2.0 Imports: 28 Imported by: 61

Documentation

Index

Constants

View Source
const (
	// RFC3339Millis represents a ISO8601 format to millis instead of to nanos
	RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
	// RFC3339Micro represents a ISO8601 format to micro instead of to nano
	RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"
	// DateTimePattern pattern to match for the date-time format from http://tools.ietf.org/html/rfc3339#section-5.6
	DateTimePattern = `^([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]+)?(z|([+-][0-9]{2}:[0-9]{2}))$`

	// RFC3339FullDate represents a full-date as specified by RFC3339
	// See: http://goo.gl/xXOvVd
	RFC3339FullDate = "2006-01-02"
)
View Source
const RequestIDContextKey = "fn_request_id"

RequestIDContextKey is the name of the key used to store the request ID into the context

View Source
const RetryForever uint64 = math.MaxUint64

Variables

View Source
var (

	// MarshalFormat sets the time resolution format used for marshaling time (set to milliseconds)
	MarshalFormat = RFC3339Millis
)

Functions

func AddCA

func AddCA(tlsConf *tls.Config, caPath string) error

AddCA adds a ca cert to the given tls config

func AddClientCA

func AddClientCA(tlsConf *tls.Config, clientCAPath string) error

AddClientCA adds a client cert to the given tls config

func BackgroundContext

func BackgroundContext(ctx context.Context) context.Context

BackgroundContext returns a context that is specifically not a child of the provided parent context wrt any cancellation or deadline of the parent, so that it contains all values only.

func CreateView

func CreateView(measure stats.Measure, agg *view.Aggregation, tagKeys []string) *view.View

func CreateViewWithTags

func CreateViewWithTags(measure stats.Measure, agg *view.Aggregation, tags []tag.Key) *view.View

func FnRequestID

func FnRequestID(ridFound string) string

FnRequestID returns the passed value if that is not empty otherwise it generates a new unique ID

func GenerateLinearHistogramBuckets added in v0.3.731

func GenerateLinearHistogramBuckets(min, max float64, count int) []float64

GenerateLinearHistogramBuckets generates number of buckets specified by count in the range specified by min and max

func GenerateLogScaleHistogramBuckets added in v0.3.731

func GenerateLogScaleHistogramBuckets(max float64, count int) []float64

GenerateLogScaleHistogramBuckets generates number of buckets specified by count on the log scale such that the value specified by max is in the last bucket

func GenerateLogScaleHistogramBucketsWithRange added in v0.3.731

func GenerateLogScaleHistogramBucketsWithRange(min, max float64) []float64

GenerateLogScaleHistogramBucketsWithRange generates histogram buckets on the log scale between the specified min and max range, such that the min value is in the first bucket and the max in the last.

func GetEnv added in v0.3.698

func GetEnv(key, fallback string) string

GetEnv looks up a key under its name in env or name+_FILE to read the value from a file. fallback will be defaulted to if a value is not found.

func GetEnvDuration added in v0.3.698

func GetEnvDuration(key string, fallback time.Duration) time.Duration

GetEnvDuration looks up a key under its name in env or name+_FILE to read the value from a file. fallback will be defaulted to if a value is not found. if an integer is provided, the value will be returned in seconds (value * time.Second)

func GetEnvInt added in v0.3.698

func GetEnvInt(key string, fallback int) int

GetEnvInt looks up a key under its name in env or name+_FILE to read the value from a file. fallback will be defaulted to if a value is not found.

func IsDate

func IsDate(str string) bool

IsDate returns true when the string is a valid date

func IsDateTime

func IsDateTime(str string) bool

IsDateTime returns true when the string is a valid date-time

func IsTemporary

func IsTemporary(err error) bool

func Logger

func Logger(ctx context.Context) logrus.FieldLogger

Logger returns the structured logger.

func LoggerWithFields

func LoggerWithFields(ctx context.Context, fields logrus.Fields) (context.Context, logrus.FieldLogger)

LoggerWithFields returns a child context of the provided parent that contains a logger with additional fields from the parent's logger, it returns the new child logger, as well.

func MakeKey

func MakeKey(name string) tag.Key

func MakeMeasure

func MakeMeasure(name string, desc string, unit string) *stats.Int64Measure

func MaskPassword

func MaskPassword(u *url.URL) string

MaskPassword returns a stringified URL without its password visible

func MinDuration

func MinDuration(f, s time.Duration) time.Duration

func NewClampReadCloser

func NewClampReadCloser(buf io.ReadCloser, max uint64, overflowErr error) io.ReadCloser

func NewClampWriter

func NewClampWriter(buf io.Writer, max uint64, overflowErr error) io.Writer

NewClamWriter creates a clamp writer that will limit the number of bytes written to to an underlying stream This allows up to max bytes to be written to the underlying stream , writes that exceed this will return overflowErr

Setting a max of 0 sets no limit

If a write spans the last remaining bytes available the number of bytes up-to the limit will be written and the overflow error will be returned

func NewSyslogHook

func NewSyslogHook(url *url.URL, prefix string) error

func NewTLSSimple

func NewTLSSimple(certPath, keyPath string) (*tls.Config, error)

NewTLSSimple creates a new tls config with the given cert and key file paths

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext extract the request id from the context

func SetLogDest

func SetLogDest(to, prefix string)

func SetLogFormat

func SetLogFormat(format string)

func SetLogLevel

func SetLogLevel(ll string)

func StripHopHeaders added in v0.3.702

func StripHopHeaders(hdr http.Header)

StripHopHeaders removes transport related headers.

func WithLogger

func WithLogger(ctx context.Context, l logrus.FieldLogger) context.Context

WithLogger stores the logger.

func WithRequestID

func WithRequestID(ctx context.Context, rid string) context.Context

WithRequestID stores a request ID into the context

Types

type BackOff added in v0.3.673

type BackOff interface {
	NextBackOff() (time.Duration, bool)
}

func NewBackOff added in v0.3.673

func NewBackOff(cfg BackOffConfig) BackOff

type BackOffConfig added in v0.3.673

type BackOffConfig struct {
	MaxRetries uint64 `json:"max_retries"`
	Interval   uint64 `json:"interval_msec"`
	MaxDelay   uint64 `json:"max_delay_msec"`
	MinDelay   uint64 `json:"min_delay_msec"`
}

type Clock

type Clock interface {
	Now() time.Time
	Sleep(time.Duration)
	After(time.Duration) <-chan time.Time
}

type DateTime

type DateTime time.Time

DateTime is a time but it serializes to ISO8601 format with millis It knows how to read 3 different variations of a RFC3339 date time. Most APIs we encounter want either millisecond or second precision times. This just tries to make it worry-free.

func NewDateTime

func NewDateTime() DateTime

NewDateTime is a representation of zero value for DateTime type

func ParseDateTime

func ParseDateTime(data string) (DateTime, error)

ParseDateTime parses a string that represents an ISO8601 time or a unix epoch

func (DateTime) MarshalText

func (t DateTime) MarshalText() ([]byte, error)

MarshalText implements the text marshaller interface

func (*DateTime) Scan

func (t *DateTime) Scan(raw interface{}) error

Scan scans a DateTime value from database driver type.

func (DateTime) String

func (t DateTime) String() string

String converts this time to a string

func (*DateTime) UnmarshalText

func (t *DateTime) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller interface

func (DateTime) Value

func (t DateTime) Value() (driver.Value, error)

Value converts DateTime to a primitive value ready to written to a database.

type GhostReader

type GhostReader interface {
	io.Reader
	io.Closer
	Swap(r io.Reader) io.Reader
}

func NewGhostReader

func NewGhostReader() GhostReader

type GhostWriter

type GhostWriter interface {
	io.Writer
	io.Closer
	Swap(r io.Writer) io.Writer
}

func NewGhostWriter

func NewGhostWriter() GhostWriter

type NoopReadWriteCloser added in v0.3.618

type NoopReadWriteCloser struct{}

NoopReadWriteCloser implements io.ReadWriteCloser, discarding all bytes, Read always returns EOF

func (NoopReadWriteCloser) Close added in v0.3.618

func (n NoopReadWriteCloser) Close() error

Close implements io.Closer

func (NoopReadWriteCloser) Read added in v0.3.618

func (n NoopReadWriteCloser) Read(b []byte) (int, error)

Read implements io.Reader

func (NoopReadWriteCloser) Write added in v0.3.618

func (n NoopReadWriteCloser) Write(b []byte) (int, error)

Write implements io.Writer

type Temporary

type Temporary interface {
	Temporary() bool
}

type Timer added in v0.3.703

type Timer struct {
	*time.Timer
}

Timer is exactly the same semantics as time.Timer, except for Reset, which fixes a deficiency from the stdlib that would have resulted in our case as a desirable behavior change to fix. See Reset for details. NewTimer must be called in order to get a Timer or there will be panics.

func NewTimer added in v0.3.703

func NewTimer(d time.Duration) Timer

NewTimer starts a new Timer with the given duration.

func (*Timer) Reset added in v0.3.703

func (t *Timer) Reset(d time.Duration) bool

Reset behaves as both Stop and Reset, draining its channel before calling reset. It differs from the stdlib Timer.Reset by being safe to call on an 'active' timer, that is, a timer that has not yet fired. see https://golang.org/pkg/time/#Timer.Reset for more details. Reset must not be called while while any other goroutine is receiving from t.C.

type WaitGroup

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

func NewWaitGroup

func NewWaitGroup() *WaitGroup

func (*WaitGroup) AddSession

func (r *WaitGroup) AddSession(delta uint64) bool

AddSession manipulates the session counter by adding the delta value. Incrementing the session counter is not possible and will set return value to false if a close was initiated.

func (*WaitGroup) CloseGroup

func (r *WaitGroup) CloseGroup()

CloseGroup initiates a close and blocks until session counter becomes zero.

func (*WaitGroup) CloseGroupNB

func (r *WaitGroup) CloseGroupNB() chan struct{}

CloseGroupNB is non-blocking version of CloseGroup which returns a channel that can be waited on.

func (*WaitGroup) Closer

func (r *WaitGroup) Closer() chan struct{}

Closer returns a channel that is closed if WaitGroup is in closing state

func (*WaitGroup) DoneSession

func (r *WaitGroup) DoneSession()

DoneSession decrements 1 from accumulated sessions and wakes up listeners when this reaches zero.

Jump to

Keyboard shortcuts

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