context.go 292 B

1234567891011121314
  1. package logger
  2. import "context"
  3. type loggerKey struct{}
  4. func FromContext(ctx context.Context) (*Helper, bool) {
  5. l, ok := ctx.Value(&loggerKey{}).(*Helper)
  6. return l, ok
  7. }
  8. func NewContext(ctx context.Context, l *Helper) context.Context {
  9. return context.WithValue(ctx, &loggerKey{}, l)
  10. }