flu

package module
v0.9.35 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: GPL-3.0 Imports: 20 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AwaitSignal

func AwaitSignal(signals ...os.Signal)

func Close

func Close(value interface{}) error

Close attempts to close the provided value using io.Closer interface.

func CloseQuietly

func CloseQuietly(value interface{})

CloseQuietly attempts to close the provided value using io.Closer with logging on error.

func Copy

func Copy(in Input, out Output) (written int64, err error)

Copy copies the Input to the Output.

func DecodeFrom

func DecodeFrom(in Input, decoder DecoderFrom) error

DecodeFrom decodes the provided DecoderFrom from Input. It closes the io.Reader instance if necessary.

func EncodeTo

func EncodeTo(encoder EncoderTo, out Output) error

EncodeTo encodes the provided EncoderTo to Output. It closes the io.Writer instance if necessary.

func IsContextRelated

func IsContextRelated(err error) bool

func IsNetworkRelated

func IsNetworkRelated(err error) bool

func Sleep

func Sleep(ctx context.Context, timeout time.Duration) error

Sleep sleeps for the specified timeout interruptibly.

func ToString

func ToString(in Input) (string, error)

ToString reads an Input to a string.

Types

type AnyCloser

type AnyCloser struct {
	V interface{}
}

AnyCloser wraps the provided value with io.Closer interface.

func (AnyCloser) Close

func (c AnyCloser) Close() error

type ByteBuffer

type ByteBuffer bytes.Buffer

ByteBuffer is an Input / Output wrapper around bytes.Buffer.

func (*ByteBuffer) Bytes

func (b *ByteBuffer) Bytes() Bytes

Bytes returns read-only Bytes view on this buffer.

func (*ByteBuffer) Reader

func (b *ByteBuffer) Reader() (io.Reader, error)

func (*ByteBuffer) Unmask

func (b *ByteBuffer) Unmask() *bytes.Buffer

Unmask returns the underlying *bytes.Buffer.

func (*ByteBuffer) Writer

func (b *ByteBuffer) Writer() (io.Writer, error)

type Bytes

type Bytes []byte

Bytes is a read-only byte array.

func (Bytes) Reader

func (b Bytes) Reader() (io.Reader, error)

func (Bytes) String added in v0.9.31

func (b Bytes) String() string

type Chars

type Chars struct {
	// In is the underlying Input.
	In Input
	// Out is the underlying Output.
	Out Output
	// Enc will be used for decoding characters from Input
	// and/or encoding them to Output.
	Enc encoding.Encoding
}

Chars is the text character Input / Output wrapper.

func (Chars) Reader

func (cs Chars) Reader() (io.Reader, error)

func (Chars) Writer

func (cs Chars) Writer() (io.Writer, error)

type Clock

type Clock interface {
	Now() time.Time
}
var DefaultClock Clock = ClockFunc(time.Now)

type ClockFunc

type ClockFunc func() time.Time

func (ClockFunc) Now

func (fun ClockFunc) Now() time.Time

type Codec

type Codec func(interface{}) ValueCodec

type Conn

type Conn struct {
	// Dialer is the net.Dialer to be used for connection.
	// May be empty.
	Dialer net.Dialer

	// Context is the context.ctx to be used.
	// May be empty.
	Context context.Context

	// Network is the network passed to Dialer.Dial.
	Network string

	// Address is the address passed to Dialer.Dial.
	Address string
}

Conn provides the means for opening net.Conn.

func (Conn) Dial

func (c Conn) Dial() (net.Conn, error)

Dial opens a net.Conn using the provided struct fields.

func (Conn) Reader

func (c Conn) Reader() (io.Reader, error)

func (Conn) Writer

func (c Conn) Writer() (io.Writer, error)

type ContextFunc

type ContextFunc func(parent context.Context) (context.Context, context.CancelFunc)

func Deadline

func Deadline(deadline time.Time) ContextFunc

func Timeout

func Timeout(timeout time.Duration) ContextFunc

type Counter

type Counter int64

Counter is an int64 counter.

func (*Counter) Add

func (c *Counter) Add(n int64)

Add adds an int64 value to the counter.

func (*Counter) Value

func (c *Counter) Value() int64

Value returns the current value of the *Counter.

type DecoderFrom

type DecoderFrom interface {
	// DecodeFrom decodes the value from the given io.Reader.
	DecodeFrom(io.Reader) error
}

DecoderFrom interface describes a value which can be decoded.

type Duration

type Duration time.Duration

func (*Duration) FromString

func (d *Duration) FromString(str string) error

func (Duration) GetOrDefault

func (d Duration) GetOrDefault(defaultValue time.Duration) time.Duration

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(node *yaml.Node) error

func (Duration) Unmask

func (d Duration) Unmask() time.Duration

type EncoderTo

type EncoderTo interface {
	// EncodeTo encodes the value to the given io.Writer.
	EncodeTo(io.Writer) error
}

EncoderTo interface describes a value which can be encoded.

type File

type File string

File is a path representing a file (or directory).

func FilePath

func FilePath(path ...string) File

FilePath creates a File instance from the provided path parts.

func (File) Create

func (f File) Create() (*os.File, error)

Create opens the File for writing. It creates the file and all intermediate directories if necessary.

func (File) Exists

func (f File) Exists() (bool, error)

Exists checks for the existence of the File entry.

func (File) Join

func (f File) Join(child string) File

Join creates a new File instance pointing to the child element of this instance.

func (File) Open

func (f File) Open() (*os.File, error)

Open opens the File for reading.

func (File) Path

func (f File) Path() string

Path returns the underlying string.

func (File) Reader

func (f File) Reader() (io.Reader, error)

func (File) Remove

func (f File) Remove() error

Remove removes the file or directory represented by this File.

func (File) Writer

func (f File) Writer() (io.Writer, error)

type IO

type IO struct {
	// R is an io.Reader instance to be used for reading.
	R io.Reader
	// W is an io.Writer instance to be used for reading.
	W io.Writer
	// E is an error which will be returned when reading/writing.
	E error
}

IO is a generic Input / Output. It is not mandatory to fill all struct fields.

func (IO) Reader

func (io IO) Reader() (io.Reader, error)

func (IO) Writer

func (io IO) Writer() (io.Writer, error)

type IOCounter

type IOCounter struct {
	Input
	Output
	Counter
}

func (*IOCounter) Reader

func (c *IOCounter) Reader() (r io.Reader, err error)

func (*IOCounter) Writer

func (c *IOCounter) Writer() (w io.Writer, err error)

type Input

type Input interface {
	// Reader returns an instance of io.Reader.
	Reader() (io.Reader, error)
}

Input interface describes a resource which can be read (possibly more than once).

func PipeInput

func PipeInput(encoder EncoderTo) Input

PipeInput pipes the encoded value from EncoderTo as Input in the background.

type Mutex

type Mutex struct {
	sync.Mutex
}

func (*Mutex) Lock

func (mu *Mutex) Lock() Unlocker

func (*Mutex) Unlock

func (mu *Mutex) Unlock()

type Output

type Output interface {
	// Writer returns an instance of io.Writer.
	Writer() (io.Writer, error)
}

Output interface describes a resource which can be written (possibly more than once).

func PipeOutput

func PipeOutput(decoder DecoderFrom) Output

PipeOutput provides an Output which feeds into DecoderFrom in the background.

type RWMutex

type RWMutex struct {
	sync.RWMutex
}

func (*RWMutex) Lock

func (mu *RWMutex) Lock() Unlocker

func (*RWMutex) RLock

func (mu *RWMutex) RLock() Unlocker

func (*RWMutex) RUnlock

func (mu *RWMutex) RUnlock()

func (*RWMutex) Unlock

func (mu *RWMutex) Unlock()

type RateLimiter

type RateLimiter interface {
	Start(ctx context.Context) error
	Complete()
}
var RateUnlimiter RateLimiter = rateUnlimiter{}

func ConcurrencyRateLimiter

func ConcurrencyRateLimiter(concurrency int) RateLimiter

func IntervalRateLimiter

func IntervalRateLimiter(interval time.Duration) RateLimiter

type ReaderCounter

type ReaderCounter struct {
	io.Reader
	*Counter
}

ReaderCounter is a counting io.Reader. Useful for calculating the total size of read data.

func (ReaderCounter) Close

func (rc ReaderCounter) Close() error

func (ReaderCounter) Read

func (rc ReaderCounter) Read(data []byte) (n int, err error)

type Text

type Text struct {
	Value string
}

Text encodes/decodes the provided value as plain text.

func (*Text) ContentType

func (v *Text) ContentType() string

func (*Text) DecodeFrom

func (v *Text) DecodeFrom(r io.Reader) error

func (*Text) EncodeTo

func (v *Text) EncodeTo(w io.Writer) error

type URL

type URL string

URL is a read-only resource accessible by URL.

func (URL) Reader

func (u URL) Reader() (io.Reader, error)

func (URL) Unmask

func (u URL) Unmask() string

Unmask returns the underlying string.

type Unlocker

type Unlocker interface {
	Unlock()
}

type UnlockerFunc

type UnlockerFunc func()

func (UnlockerFunc) Unlock

func (fun UnlockerFunc) Unlock()

type ValueCodec

type ValueCodec interface {
	EncoderTo
	DecoderFrom
}

func Gob

func Gob(value interface{}) ValueCodec

func JSON

func JSON(value interface{}) ValueCodec

JSON encodes/decodes the provided ValueCodec using JSON format.

func XML

func XML(value interface{}) ValueCodec

func YAML

func YAML(value interface{}) ValueCodec

type WaitGroup

type WaitGroup struct {
	sync.WaitGroup
}

func (*WaitGroup) Go

func (wg *WaitGroup) Go(ctx context.Context, fun func(ctx context.Context)) func()

func (*WaitGroup) GoWith

func (wg *WaitGroup) GoWith(ctx context.Context, contextFunc ContextFunc, fun func(ctx context.Context)) func()

type WriterCounter

type WriterCounter struct {
	io.Writer
	*Counter
}

WriterCounter is a counting io.Writer. Useful for calculating the total size of written data.

func (WriterCounter) Close

func (wc WriterCounter) Close() error

func (WriterCounter) Write

func (wc WriterCounter) Write(data []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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