utils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxIngestID

func CtxIngestID(ctx context.Context) (types.IngestID, context.Context)

CtxIngestID returns stream ID from context. If stream ID is not set, return new stream ID and context with it

func CtxLogger

func CtxLogger(ctx context.Context) *slog.Logger

CtxLogger returns logger from context. If logger is not set, return default logger

func CtxRequestID

func CtxRequestID(ctx context.Context) (types.RequestID, context.Context)

CtxRequestID returns request ID from context. If request ID is not set, return new request ID and context with it

func CtxTime added in v0.1.0

func CtxTime(ctx context.Context) time.Time

CtxTime returns time from context. If time is not set, return current time and context with it

func CtxWithLogger

func CtxWithLogger(ctx context.Context, logger *slog.Logger) context.Context

WithLogger returns a new context with logger

func CtxWithTime added in v0.1.0

func CtxWithTime(ctx context.Context, timeFunc TimeFunc) context.Context

CtxWithTime returns a new context with time function

func ErrLog

func ErrLog(err error) slog.Attr

func HandleError

func HandleError(ctx context.Context, msg string, err error)

func LoadEnv

func LoadEnv(t *testing.T, key string) string

func Logger

func Logger() *slog.Logger

func SafeClose

func SafeClose(c Closer)

func SafeWrite

func SafeWrite(w io.Writer, b []byte)

func SetLogger

func SetLogger(l *slog.Logger)

Types

type Closer

type Closer interface {
	Close() error
}

type TimeFunc added in v0.1.0

type TimeFunc func() time.Time

Jump to

Keyboard shortcuts

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