Documentation ¶
Index ¶
- Variables
- func AwaitSignal(signals ...os.Signal)
- func Close(value interface{}) error
- func CloseQuietly(value interface{})
- func Copy(in Input, out Output) (written int64, err error)
- func DecodeFrom(in Input, decoder DecoderFrom) error
- func EncodeTo(encoder EncoderTo, out Output) error
- func IsContextRelated(err error) bool
- func IsNetworkRelated(err error) bool
- func Sleep(ctx context.Context, timeout time.Duration) error
- func ToString(in Input) (string, error)
- type AnyCloser
- type ByteBuffer
- type Bytes
- type Chars
- type Clock
- type ClockFunc
- type Codec
- type Conn
- type ContextFunc
- type Counter
- type DecoderFrom
- type Duration
- type EncoderTo
- type File
- func (f File) Append() (*os.File, error)
- func (f File) Create() (*os.File, error)
- func (f File) CreateParent() error
- func (f File) Exists() (bool, error)
- func (f File) Join(child string) File
- func (f File) Open() (*os.File, error)
- func (f File) Path() string
- func (f File) Reader() (io.Reader, error)
- func (f File) Remove() error
- func (f File) Writer() (io.Writer, error)
- type IO
- type IOCounter
- type Input
- type Int64Set
- func (s Int64Set) Add(values ...int64) Int64Set
- func (s Int64Set) Copy() Int64Set
- func (s Int64Set) MarshalJSON() ([]byte, error)
- func (s Int64Set) MarshalYAML() (interface{}, error)
- func (s Int64Set) Slice() []int64
- func (s *Int64Set) UnmarshalJSON(data []byte) error
- func (s *Int64Set) UnmarshalYAML(node *yaml.Node) error
- type Mutex
- type Output
- type RWMutex
- type RateLimiter
- type ReaderCounter
- type StringSet
- func (s StringSet) Add(values ...string) StringSet
- func (s StringSet) AnyMatch(matcher func(key string) bool) bool
- func (s StringSet) Copy() StringSet
- func (s StringSet) MarshalJSON() ([]byte, error)
- func (s StringSet) MarshalYAML() (interface{}, error)
- func (s StringSet) Slice() []string
- func (s *StringSet) UnmarshalJSON(data []byte) error
- func (s *StringSet) UnmarshalYAML(node *yaml.Node) error
- type Text
- type Time
- type URL
- type Unlocker
- type UnlockerFunc
- type ValueCodec
- type WaitGroup
- type WriterCounter
Constants ¶
This section is empty.
Variables ¶
var TimeLayout = "2006-01-02 15:04:05"
TimeLayout is the default layout used while parsing Time from a string.
Functions ¶
func AwaitSignal ¶
AwaitSignal blocks until a signal is received. By default listens to SIGINT, SIGABRT, SIGKILL, SIGTERM.
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 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 ¶
EncodeTo encodes the provided EncoderTo to Output. It closes the io.Writer instance if necessary.
func IsContextRelated ¶
IsContextRelated checks if this is a "context" package error.
func IsNetworkRelated ¶
IsNetworkRelated checks if this is a net.Error.
Types ¶
type AnyCloser ¶
type AnyCloser struct {
V interface{}
}
AnyCloser wraps the provided value with io.Closer interface.
type ByteBuffer ¶
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) Unmask ¶
func (b *ByteBuffer) Unmask() *bytes.Buffer
Unmask returns the underlying *bytes.Buffer.
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.
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.
type ContextFunc ¶
ContextFunc creates a child context.Context from a given one.
func Deadline ¶
func Deadline(deadline time.Time) ContextFunc
Deadline returns ContextFunc which uses cpntext.WithDeadline.
func Timeout ¶
func Timeout(timeout time.Duration) ContextFunc
Timeout returns ContextFunc which uses context.WithTimeout.
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 ¶
Duration provides useful serialization methods for time.Duration.
func (*Duration) FromString ¶
FromString parses the duration from a string value.
func (Duration) GetOrDefault ¶
GetOrDefault returns the value if d > 0 or the provided default value otherwise.
func (*Duration) UnmarshalJSON ¶
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 (File) Create ¶
Create opens the File for writing. It creates the file and all intermediate directories if necessary.
func (File) CreateParent ¶ added in v0.10.3
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.
type Int64Set ¶ added in v0.10.1
Int64Set emulates a int64 set.
func (Int64Set) MarshalJSON ¶ added in v0.10.1
func (Int64Set) MarshalYAML ¶ added in v0.10.1
func (Int64Set) Slice ¶ added in v0.10.1
Slice creates a slice containing all values from this set in no particular order.
func (*Int64Set) UnmarshalJSON ¶ added in v0.10.1
type Output ¶
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 ¶
RWMutex is a wrapper for stdlib sync.RWMutex providing fluent lock/unlock syntax.
var mu sync.RWMutex = ... defer mu.RLock().Unlock() // some operations which require exclusive read- and/or write-access.
type RateLimiter ¶
type RateLimiter interface { // Start "takes the lock". Start(ctx context.Context) error // Complete "releases the lock". Complete() }
RateLimiter allows to control the frequency of some action.
var RateUnlimiter RateLimiter = rateUnlimiter{}
RateUnlimiter is a no-op rate limiter.
func ConcurrencyRateLimiter ¶
func ConcurrencyRateLimiter(concurrency int) RateLimiter
ConcurrencyRateLimiter applies concurrency limit.
func IntervalRateLimiter ¶
func IntervalRateLimiter(interval time.Duration) RateLimiter
IntervalRateLimiter applies interval rate limit.
type ReaderCounter ¶
ReaderCounter is a counting io.Reader. Useful for calculating the total size of read data.
func (ReaderCounter) Close ¶
func (rc ReaderCounter) Close() error
type StringSet ¶ added in v0.10.1
StringSet emulates a string set with JSON and YAML serialization support.
func (StringSet) MarshalJSON ¶ added in v0.10.1
func (StringSet) MarshalYAML ¶ added in v0.10.1
func (StringSet) Slice ¶ added in v0.10.1
Slice returns a slice containing all values from this set in no particular order.
func (*StringSet) UnmarshalJSON ¶ added in v0.10.1
func (*StringSet) UnmarshalYAML ¶ added in v0.10.1
type Text ¶
type Text struct {
Value string
}
Text encodes/decodes the provided value as plain text.
func (*Text) ContentType ¶
type Time ¶ added in v0.10.1
Time is time.Time wrapper with serialization support.
func (*Time) FromString ¶ added in v0.10.1
FromString parses a string.
func (*Time) MarshalJSON ¶ added in v0.10.1
func (*Time) MarshalYAML ¶ added in v0.10.1
func (*Time) UnmarshalJSON ¶ added in v0.10.1
type Unlocker ¶
type Unlocker interface {
Unlock()
}
Unlocker is commonly a lock which can be unlocked.
type UnlockerFunc ¶
type UnlockerFunc func()
UnlockerFunc is a functional adapter.
func (UnlockerFunc) Unlock ¶
func (fun UnlockerFunc) Unlock()
type ValueCodec ¶
type ValueCodec interface { EncoderTo DecoderFrom }
ValueCodec is a value container with encoder and decoder.
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 ¶
WaitGroup is a sync.WaitGroup wrapper adding Go* utility methods for convenient goroutine management. Example:
ctx, cancel := context.WithCancel(context.Background()) defer cancel() var work flu.WaitGroup // wait until all goroutines finish defer work.Wait() for i := 0; i < 10; i++ { _ = work.Go(ctx, func(ctx context.Context) { // do some async work }) }
func (*WaitGroup) GoWith ¶
func (wg *WaitGroup) GoWith(ctx context.Context, contextFunc ContextFunc, fun func(ctx context.Context)) func()
GoWith starts a function with a child context created by a given ContextFunc. The sync.WaitGroup counter is incremented and decremented automatically. The child context is automatically canceled also, but is also returned for manual goroutine context cancellation. For example,
// service initialization var work flu.WaitGroup // wait for background work to finish on exit defer work.Wait() // launch a separate goroutine performing some periodic work cancel := work.Go(ctx, func(ctx context.Context) { ticker := time.NewTicker(...) defer ticker.Stop() for { select { case <-ctx.Done(): return case now := <-ticker.C: // perform some periodic work } } }) // cancel the background task on exit // can also write as defer work.Go(...)() defer cancel() // let it work for a minute and exit // this causes the context to cancel and interrupt the goroutine if err := flu.Sleep(ctx, time.Minute); err != nil { panic(err) }
type WriterCounter ¶
WriterCounter is a counting io.Writer. Useful for calculating the total size of written data.
func (WriterCounter) Close ¶
func (wc WriterCounter) Close() error
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
apfel contains utilities for generic application configuration and basic lifecycle management (setup/teardown).
|
apfel contains utilities for generic application configuration and basic lifecycle management (setup/teardown). |
me3x package contains abstractions for reporting metrics to Graphite or Prometheus.
|
me3x package contains abstractions for reporting metrics to Graphite or Prometheus. |