This commit is contained in:
Beau
2024-02-26 12:44:50 +00:00
commit 3cd7e44cb3
22 changed files with 2158 additions and 0 deletions

29
logger/logger.go Normal file
View File

@@ -0,0 +1,29 @@
package logger
import (
"context"
"go.uber.org/zap"
)
type loggerKey struct{}
// WithContext returns a new context with the logger added.
func WithContext(ctx context.Context, l *zap.Logger) context.Context {
return context.WithValue(ctx, loggerKey{}, l)
}
// FromContext returns the logger in the context if it exists, otherwise a new
// no-op logger is returned .
func FromContext(ctx context.Context) *zap.Logger {
if ctx == nil {
return zap.NewNop()
}
v := ctx.Value(loggerKey{})
if v == nil {
return zap.NewNop()
}
return v.(*zap.Logger)
}