forked from go-language-server/protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
35 lines (27 loc) · 792 Bytes
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-FileCopyrightText: 2020 The Go Language Server Authors
// SPDX-License-Identifier: BSD-3-Clause
package protocol
import (
"context"
"go.uber.org/zap"
)
var (
ctxLogger struct{}
ctxClient struct{}
)
// WithLogger returns the context with zap.Logger value.
func WithLogger(ctx context.Context, logger *zap.Logger) context.Context {
return context.WithValue(ctx, ctxLogger, logger)
}
// LoggerFromContext extracts zap.Logger from context.
func LoggerFromContext(ctx context.Context) *zap.Logger {
logger, ok := ctx.Value(ctxLogger).(*zap.Logger)
if !ok {
return zap.NewNop()
}
return logger
}
// WithClient returns the context with Client value.
func WithClient(ctx context.Context, client Client) context.Context {
return context.WithValue(ctx, ctxClient, client)
}