field

package
v0.0.0-...-9cf347b Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: BSD-3-Clause Imports: 2 Imported by: 10

Documentation

Index

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

func (f *Field) ForEachField(callback func(f *Field) bool) bool

ForEachField implements AbstractFields.

func (*Field) Len

func (f *Field) Len() int

Len 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) Copy

func (s Fields) Copy() Fields

Copy returns a copy of the slice.

func (Fields) ForEachField

func (s Fields) ForEachField(callback func(f *Field) bool) bool

ForEachField implements AbstractFields

func (Fields) Len

func (s Fields) Len() int

Len implements sort.Interface

func (Fields) Less

func (s Fields) Less(i, j int) bool

Less implements sort.Interface

func (Fields) WithPreallocate

func (s Fields) WithPreallocate(preallocateLen uint) Fields

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 Key

type Key = string

Key is an identifier of the Field.

type Map

type Map[V any] map[Key]V

Map is just a handy low performance way to pass fields similar to how it is done in logrus.

func (Map[V]) ForEachField

func (m Map[V]) ForEachField(callback func(f *Field) bool) bool

ForEachField implements AbstractFields.

func (Map[V]) Len

func (m Map[V]) Len() int

Len 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

func (p Prefixer) ForEachField(callback func(f *Field) bool) bool

ForEachField implements AbstractFields.

func (Prefixer) Len

func (p Prefixer) Len() int

Len 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

func (s Slice[T]) ForEachField(callback func(f *Field) bool) bool

ForEachField implements AbstractFields.

func (Slice[T]) Len

func (s Slice[T]) Len() int

Len 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

func (s *Slicer[T]) ForEachField(callback func(f *Field) bool) bool

ForEachField implements AbstractFields.

func (*Slicer[T]) Len

func (s *Slicer[T]) Len() int

Len implements AbstractFields.

type Value

type Value = any

Value is a value stored within a Field.

Jump to

Keyboard shortcuts

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