common

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyValueToString

func AnyValueToString(v slog.Value) string

func AppendAttrsToGroup

func AppendAttrsToGroup(groups []string, actualAttrs []slog.Attr, newAttrs ...slog.Attr) []slog.Attr

func AppendRecordAttrsToAttrs

func AppendRecordAttrsToAttrs(attrs []slog.Attr, groups []string, record *slog.Record) []slog.Attr

func AttrToValue

func AttrToValue(attr slog.Attr) (string, any)

func AttrsToMap

func AttrsToMap(attrs ...slog.Attr) map[string]any

func AttrsToString

func AttrsToString(attrs ...slog.Attr) map[string]string

func Contains added in v0.0.16

func Contains[T comparable](collection []T, element T) bool

Contains returns true if an element is present in a collection.

func ContextExtractor

func ContextExtractor(ctx context.Context, fns []func(ctx context.Context) []slog.Attr) []slog.Attr

func ExtractError

func ExtractError(attrs []slog.Attr, errorKeys ...string) ([]slog.Attr, error)

func ExtractFromContext

func ExtractFromContext(keys ...any) func(ctx context.Context) []slog.Attr

func FilterMap added in v0.0.16

func FilterMap[T any, R any](collection []T, callback func(item T, index int) (R, bool)) []R

FilterMap returns a slice which obtained after both filtering and mapping using the given callback function. The callback function should return two values:

  • the result of the mapping operation and
  • whether the result element should be included or not.

Play: https://go.dev/play/p/-AuYXfy7opz

func FindAttrByGroupAndKey

func FindAttrByGroupAndKey(attrs []slog.Attr, groups []string, key string) (slog.Attr, bool)

func FindAttrByKey

func FindAttrByKey(attrs []slog.Attr, key string) (slog.Attr, bool)

func FindAttribute

func FindAttribute(attrs []slog.Attr, groups []string, key string) (slog.Attr, bool)

func FormatError

func FormatError(err error) map[string]any

func FormatErrorKey

func FormatErrorKey(values map[string]any, errorKeys ...string) map[string]any

func FormatRequest

func FormatRequest(req *http.Request, ignoreHeaders bool) map[string]any

func Map

func Map[T any, R any](collection []T, iteratee func(item T, index int) R) []R

Map manipulates a slice and transforms it to a slice of another type. Play: https://go.dev/play/p/OkPcYAhBo0D

func MapEntries added in v0.0.16

func MapEntries[K1 comparable, V1 any, K2 comparable, V2 any](in map[K1]V1, iteratee func(key K1, value V1) (K2, V2)) map[K2]V2

MapEntries manipulates a map entries and transforms it to a map of another type. Play: https://go.dev/play/p/VuvNQzxKimT

func MapToSlice added in v0.0.16

func MapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(key K, value V) R) []R

MapToSlice transforms a map into a slice based on specific iteratee Play: https://go.dev/play/p/ZuiCZpDt6LD

func RemoveEmptyAttrs

func RemoveEmptyAttrs(attrs []slog.Attr) []slog.Attr

func ReplaceAttrs

func ReplaceAttrs(fn ReplaceAttrFn, groups []string, attrs ...slog.Attr) []slog.Attr

func ReplaceError

func ReplaceError(attrs []slog.Attr, errorKeys ...string) []slog.Attr

func Source

func Source(sourceKey string, r *slog.Record) slog.Attr

func StringSource

func StringSource(sourceKey string, r *slog.Record) slog.Attr

func ToAnySlice added in v0.0.16

func ToAnySlice[T any](collection []T) []any

ToAnySlice returns a slice with all elements mapped to `any` type

func UniqAttrs

func UniqAttrs(attrs []slog.Attr) []slog.Attr

@TODO: should be recursive

func ValueToString

func ValueToString(v slog.Value) string

Types

type ReplaceAttrFn

type ReplaceAttrFn = func(groups []string, a slog.Attr) slog.Attr

Jump to

Keyboard shortcuts

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