mirror of
https://github.com/gomods/athens
synced 2026-02-03 14:20:31 +00:00
* feat: add golangci-lint linting * chore: fix linter issues * feat: add linting into the workflow * docs: update lint docs * fix: cr suggestions * fix: remove old formatting and vetting scripts * fix: add docker make target * fix: action go caching * fix: depreciated actions checkout version * fix: cr suggestion * fix: cr suggestions --------- Co-authored-by: Manu Gupta <manugupt1@gmail.com>
26 lines
640 B
Go
26 lines
640 B
Go
package log
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type ctxKey string
|
|
|
|
const logEntryKey ctxKey = "log-entry-context-key"
|
|
|
|
// SetEntryInContext stores an Entry in the request context.
|
|
func SetEntryInContext(ctx context.Context, e Entry) context.Context {
|
|
return context.WithValue(ctx, logEntryKey, e)
|
|
}
|
|
|
|
// EntryFromContext returns an Entry that has been stored in the request context.
|
|
// If there is no value for the key or the type assertion fails, it returns a new
|
|
// entry from the provided logger.
|
|
func EntryFromContext(ctx context.Context) Entry {
|
|
e, ok := ctx.Value(logEntryKey).(Entry)
|
|
if !ok || e == nil {
|
|
return NoOpLogger()
|
|
}
|
|
return e
|
|
}
|