Documentation ¶
Index ¶
- type AbstractFields
- type Field
- type Fields
- type FieldsChain
- func (fields *FieldsChain) ForEachField(callback func(f *Field) bool) bool
- func (fields *FieldsChain) GoString() string
- func (fields *FieldsChain) Len() int
- func (fields *FieldsChain) WithField(key Key, value Value, props ...Property) *FieldsChain
- func (fields *FieldsChain) WithFields(add AbstractFields) *FieldsChain
- func (fields *FieldsChain) WithMap(m map[Key]interface{}, props ...Property) *FieldsChain
- type ForEachFieldser
- type Key
- type Map
- type MapGeneric
- type Prefixer
- type Properties
- type Property
- type Slice
- type Slicer
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AbstractFields ¶
type AbstractFields interface { ForEachFieldser Len() int }
AbstractFields is an abstraction of any types of collections of fields.
func Add ¶
func Add(in ...AbstractFields) AbstractFields
Add adds collections of fields together into a bigger collection.
type Field ¶
type Field struct { // Key is the identifier of the field. They are supposed to be unique, // but this is not a mandatory requirement. Each tool implementation // may treat duplicated keys differently. Key Key // Value is the value. Value // Properties defines Hook-specific options (how to interpret the specific field). Properties Properties }
Field represents a single structured value.
func (*Field) ForEachField ¶
ForEachField implements AbstractFields.
type Fields ¶
type Fields []Field
Fields is a slice of Field-s
func Gather ¶
func Gather[T AbstractFields](fields T) Fields
Gather copies all the fields into a slice and returns it.
func (Fields) ForEachField ¶
ForEachField implements AbstractFields
func (Fields) WithPreallocate ¶
WithPreallocate returns a copy of the slice with available additional capacity of size preallocateLen.
type FieldsChain ¶
type FieldsChain struct {
// contains filtered or unexported fields
}
FieldsChain is a chain of fields.
FieldsChain is focused on high-performance Clone method.
func NewChainFromOne ¶
func NewChainFromOne(key Key, value Value, props ...Property) *FieldsChain
NewChainFromOne returns a FieldsChain which contains only one Field.
func (*FieldsChain) ForEachField ¶
func (fields *FieldsChain) ForEachField(callback func(f *Field) bool) bool
ForEachField implements AbstractFields
func (*FieldsChain) GoString ¶
func (fields *FieldsChain) GoString() string
GoString implements fmt.GoStringer
func (*FieldsChain) Len ¶
func (fields *FieldsChain) Len() int
Len returns the total amount of fields reported by ForEachField. T: O(n)
Implements AbstractFields
func (*FieldsChain) WithField ¶
func (fields *FieldsChain) WithField(key Key, value Value, props ...Property) *FieldsChain
WithField adds the field to the chain (from the forward -- FIFO) and returns the pointer to the new beginning.
func (*FieldsChain) WithFields ¶
func (fields *FieldsChain) WithFields(add AbstractFields) *FieldsChain
WithFields adds the fields to the chain (from the forward -- FIFO) and returns the pointer to the new beginning.
func (*FieldsChain) WithMap ¶
func (fields *FieldsChain) WithMap(m map[Key]interface{}, props ...Property) *FieldsChain
WithMap adds the fields constructed from the map to the chain (from the forward -- FIFO) and returns the pointer to the new beginning.
type ForEachFieldser ¶
type ForEachFieldser interface { // ForEachField iterates through all the fields, until first false is returned. // // WARNING! This callback is supposed to be used only to read // the field content, but not to hold the pointer to the field itself. // For the purposes of performance optimizations it is assumed // that the pointer is not escapable. If it is required to store // the pointer to the field after `callback` returned then copy the field. // Otherwise Go's memory guarantees are broken. ForEachField(callback func(f *Field) bool) bool }
ForEachFieldser is an iterator through a collection of fields.
Any object which implements this interface may be used as a source of fields. For example a generic parser of field values in a Logger checks if a value implements this interface, and if does, then it is used to provide the fields instead of using a generic method.
type Map ¶
Map is just a handy low performance way to pass fields similar to how it is done in logrus.
func (Map[V]) ForEachField ¶
ForEachField implements AbstractFields.
type MapGeneric ¶
type MapGeneric[K comparable, V any] map[K]V
Map is an abstract map which implements field.AbstractFields.
It differs from Map, because it also accepts non-string keys.
func (MapGeneric[K, V]) ForEachField ¶
func (m MapGeneric[K, V]) ForEachField(callback func(f *Field) bool) bool
ForEachField implements field.AbstractFields.
func (MapGeneric[K, V]) Len ¶
func (m MapGeneric[K, V]) Len() int
Len implements field.AbstractFields.
type Prefixer ¶
type Prefixer struct { Prefix string Fields AbstractFields }
Prefixer adds Prefix to Key-s of all fields.
TODO: redesign this, see: https://github.com/facebookincubator/go-belt/issues/6
func Prefix ¶
func Prefix(prefix string, fields AbstractFields) Prefixer
Prefix adds Prefix to Key-s of all fields.
func (Prefixer) ForEachField ¶
ForEachField implements AbstractFields.
type Properties ¶
type Properties []Property
Properties defines Tool-specific options (how to interpret the specific field).
func (Properties) Has ¶
func (s Properties) Has(p Property) bool
Has returns true if the Properties contains the specific property (equals both by type and value).
type Property ¶
type Property interface{}
Property defines a Tool-specific option (how to interpret the specific field).
type Slice ¶
type Slice[T AbstractFields] []T
Slice is a collection of collections of fields.
func (Slice[T]) ForEachField ¶
ForEachField implements AbstractFields.
type Slicer ¶
type Slicer[T AbstractFields] struct { All T StartIdx uint EndIdx uint }
Slicer implements AbstractFields providing a subset of fields (reported through method ForEachField of the initial collection).
func NewSlicer ¶
func NewSlicer[T AbstractFields](all T, startIdx, endIdx uint) *Slicer[T]
NewSlicer provides a subset of fields (reported through method ForEachField of the initial collection).
func (*Slicer[T]) ForEachField ¶
ForEachField implements AbstractFields.