common

package
v0.0.0-...-235d2ce Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: Apache-2.0 Imports: 16 Imported by: 36

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTemporary

func IsTemporary(err error) bool

func IsUserVisibleError

func IsUserVisibleError(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)

Attempt at simplifying this whole logger in the context thing Could even make this take a generic map, then the logger that gets returned could be used just like the stdlib too, since it's compatible

func NewRNG

func NewRNG(seed int64) *rand.Rand

func NewSyslogHook

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

func SetLogDest

func SetLogDest(to, prefix string)

func SetLogLevel

func SetLogLevel(ll string)

func UserError

func UserError(err error) error

func WithLogger

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

WithLogger stores the logger.

Types

type Backoff

type Backoff int

func (*Backoff) RandomSleep

func (b *Backoff) RandomSleep(rng *rand.Rand, clock Clock)

func (*Backoff) Sleep

func (b *Backoff) Sleep()

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 Environment

type Environment struct {
	stats.Statter
}

func NewEnvironment

func NewEnvironment(initializers ...func(e *Environment)) *Environment

Initializers are functions that may set up the environment as they like. By default the environment is 'inactive' in the sense that metrics aren't reported.

type HeadLinesWriter

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

HeadLinesWriter stores upto the first N lines in a buffer that can be retrieved via Head().

func NewHeadLinesWriter

func NewHeadLinesWriter(max int) *HeadLinesWriter

func (*HeadLinesWriter) Head

func (h *HeadLinesWriter) Head() []byte

The returned bytes alias the buffer, the same restrictions as bytes.Buffer.Bytes() apply.

func (*HeadLinesWriter) Write

func (h *HeadLinesWriter) Write(p []byte) (n int, err error)

Writes start failing once the writer has reached capacity. In such cases the return value is the actual count written (may be zero) and io.ErrShortWrite.

type LineWriter

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

lineWriter will break apart a stream of data into individual lines. Downstream writer will be called for each complete new line. When Flush is called, a newline will be appended if there isn't one at the end. Not thread-safe

func NewLineWriter

func NewLineWriter(w io.Writer) *LineWriter

func (*LineWriter) Flush

func (li *LineWriter) Flush() (int, error)

func (*LineWriter) Write

func (li *LineWriter) Write(p []byte) (int, error)

type TailLinesWriter

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

TailLinesWriter stores upto the last N lines in a buffer that can be retrieved via Tail(). The truncation is only performed when more bytes are received after '\n', so the buffer contents for both these writes are identical.

tail writer that captures last 3 lines. 'a\nb\nc\nd\n' -> 'b\nc\nd\n' 'a\nb\nc\nd' -> 'b\nc\nd'

func NewTailLinesWriter

func NewTailLinesWriter(max int) *TailLinesWriter

func (*TailLinesWriter) Tail

func (t *TailLinesWriter) Tail() []byte

The returned bytes alias the buffer, the same restrictions as bytes.Buffer.Bytes() apply.

Once Tail() is called, further Write()s error.

func (*TailLinesWriter) Write

func (t *TailLinesWriter) Write(p []byte) (n int, err error)

Write always succeeds! This is because all len(p) bytes are written to the buffer before it is truncated.

type Temporary

type Temporary interface {
	Temporary() bool
}

type UserVisibleError

type UserVisibleError interface {
	UserVisible() bool
}

Errors that can be directly exposed to task creators/users.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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