flu

package module
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2022 License: GPL-3.0 Imports: 19 Imported by: 14

README

flu

ci Go Reference

A collection of common utilities used throughout my projects.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ID       = internal.ID
	Readable = internal.Readable
)
View Source
var TimeLayout = "2006-01-02 15:04:05"

TimeLayout is the default layout used while parsing Time from a string.

Functions

func AppendAll added in v0.10.5

func AppendAll[E any](appendable Appendable[E], iterable Iterable[E])

func Close

func Close(value any) error

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

func CloseQuietly

func CloseQuietly(values ...any)

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

func Contains added in v0.10.5

func Contains[E comparable](iterable Iterable[E], value E) (match bool)

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 IsNetworkRelated

func IsNetworkRelated(err error) bool

IsNetworkRelated checks if this is a net.Error.

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

AnyCloser wraps the provided value with io.Closer interface.

func (AnyCloser) Close

func (c AnyCloser) Close() error

type Appendable added in v0.10.5

type Appendable[E any] interface{ Append(element E) }

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 Codec

type Codec func(interface{}) ValueCodec

Codec creates a ValueCodec for a given value.

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 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 struct {
	Value time.Duration
}

Duration provides useful serialization methods for time.Duration.

func (*Duration) FromString

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

FromString parses the duration from a string value.

func (Duration) MarshalJSON added in v0.10.5

func (d Duration) MarshalJSON() ([]byte, error)

func (Duration) MarshalYAML added in v0.10.5

func (d Duration) MarshalYAML() (interface{}, error)

func (*Duration) UnmarshalJSON

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

func (*Duration) UnmarshalYAML

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

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) Append added in v0.10.3

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

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) CreateParent added in v0.10.3

func (f File) CreateParent() error

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) 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) String added in v0.10.5

func (f File) String() string

String returns the underlying string.

func (File) Writer

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

type ForEach added in v0.10.5

type ForEach[E any] func(element E) bool

type IO

type IO = internal.IO

type IOCounter

type IOCounter struct {
	Input
	Output
	Counter
}

IOCounter is a counting wrapper for Input and/or Output.

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 = internal.Input

func PipeInput

func PipeInput(encoder EncoderTo) Input

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

type Iterable added in v0.10.5

type Iterable[E any] interface{ ForEach(forEach ForEach[E]) }

type Output

type Output = internal.Output

func PipeOutput

func PipeOutput(decoder DecoderFrom) Output

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

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 Set added in v0.10.5

type Set[E constraints.Ordered] map[E]bool

func (*Set[E]) Append added in v0.10.5

func (s *Set[E]) Append(element E)

func (Set[E]) ForEach added in v0.10.5

func (s Set[E]) ForEach(forEach ForEach[E])

func (Set[E]) MarshalJSON added in v0.10.5

func (s Set[E]) MarshalJSON() ([]byte, error)

func (Set[E]) MarshalYAML added in v0.10.5

func (s Set[E]) MarshalYAML() (interface{}, error)

func (Set[E]) Size added in v0.10.5

func (s Set[E]) Size() int

func (*Set[E]) UnmarshalJSON added in v0.10.5

func (s *Set[E]) UnmarshalJSON(data []byte) error

func (*Set[E]) UnmarshalYAML added in v0.10.5

func (s *Set[E]) UnmarshalYAML(node *yaml.Node) error

type Sizeable added in v0.10.5

type Sizeable interface{ Size() int }

type Slice added in v0.10.5

type Slice[E any] []E

func ToSlice added in v0.10.5

func ToSlice[E any](iterable Iterable[E]) Slice[E]

func (*Slice[E]) Append added in v0.10.5

func (s *Slice[E]) Append(element E)

func (Slice[E]) ForEach added in v0.10.5

func (s Slice[E]) ForEach(forEach ForEach[E])

func (Slice[E]) Size added in v0.10.5

func (s Slice[E]) Size() int

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 Time added in v0.10.1

type Time struct {
	time.Time

	// Layout may be used to custom string value layout.
	Layout string
}

Time is time.Time wrapper with serialization support.

func (*Time) FromString added in v0.10.1

func (t *Time) FromString(str string) error

FromString parses a string.

func (*Time) MarshalJSON added in v0.10.1

func (t *Time) MarshalJSON() ([]byte, error)

func (*Time) MarshalYAML added in v0.10.1

func (t *Time) MarshalYAML() (interface{}, error)

func (Time) String added in v0.10.1

func (t Time) String() string

func (*Time) UnmarshalJSON added in v0.10.1

func (t *Time) UnmarshalJSON(data []byte) error

func (*Time) UnmarshalYAML added in v0.10.1

func (t *Time) UnmarshalYAML(node *yaml.Node) 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 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 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
schema
Package schema implements OpenAPI 3 compatible JSON Schema which can be generated from structs.
Package schema implements OpenAPI 3 compatible JSON Schema which can be generated from structs.
me3x package contains abstractions for reporting metrics to Graphite or Prometheus.
me3x package contains abstractions for reporting metrics to Graphite or Prometheus.

Jump to

Keyboard shortcuts

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