18 lines
329 B
Go
18 lines
329 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"log/slog"
|
||
|
)
|
||
|
|
||
|
type loggerCtxKey struct{}
|
||
|
|
||
|
func loggerToCtx(ctx context.Context, l *slog.Logger) context.Context {
|
||
|
return context.WithValue(ctx, loggerCtxKey{}, l)
|
||
|
}
|
||
|
|
||
|
func loggerFromCtx(ctx context.Context) *slog.Logger {
|
||
|
logger, _ := ctx.Value(loggerCtxKey{}).(*slog.Logger)
|
||
|
return logger
|
||
|
}
|