utils

package
v0.0.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxLogger

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

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

func CtxLoggerWith

func CtxLoggerWith(ctx context.Context, attrs ...slog.Attr) context.Context

CtxLoggerWith returns a new logger with additional fields

func CtxNow

func CtxNow(ctx context.Context) time.Time

func CtxRequestID

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

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

func CtxWithLogger

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

CtxWithLogger returns a new context with logger

func CtxWithNow

func CtxWithNow(ctx context.Context, f nowFunc) context.Context

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

LoadEnv loads the environment variable and returns it for testing. If the environment variable is not set, it skips the test.

func Logger

func Logger() *slog.Logger

func SafeClose

func SafeClose(closer io.Closer)

func SetLogger

func SetLogger(l *slog.Logger)

Types

This section is empty.

Jump to

Keyboard shortcuts

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