17 lines
342 B
Go
17 lines
342 B
Go
package contextutil
|
|
|
|
import "context"
|
|
|
|
func WithThreadName(ctx context.Context, threadName string) context.Context {
|
|
return context.WithValue(ctx, "context_thread", threadName)
|
|
}
|
|
|
|
func ThreadName(ctx context.Context) string {
|
|
value := ctx.Value("context_thread")
|
|
if value, ok := value.(string); ok {
|
|
return value
|
|
}
|
|
|
|
return "unknown"
|
|
}
|