first version
This commit is contained in:
16
contextutil/contextutil.go
Normal file
16
contextutil/contextutil.go
Normal file
@@ -0,0 +1,16 @@
|
||||
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"
|
||||
}
|
||||
Reference in New Issue
Block a user