common

package
v0.3.633 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: Apache-2.0 Imports: 26 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

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

Add CA

func AddClientCA

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

Add a Client CA

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 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

func NewRNG

func NewRNG(seed int64) *rand.Rand

func NewSyslogHook

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

func NewTLSSimple

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

A simple TLS Config generator using cert/key

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 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

type Backoff int

func (*Backoff) Sleep

func (b *Backoff) Sleep(ctx context.Context)

type BoxTime

type BoxTime struct{}

func (BoxTime) After

func (BoxTime) After(d time.Duration) <-chan time.Time

func (BoxTime) Now

func (BoxTime) Now() time.Time

func (BoxTime) Sleep

func (BoxTime) Sleep(d time.Duration)

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 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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