2020-11-26 09:19:14 +01:00

21 lines
377 B
Go

package service
import "context"
type serviceKey struct{}
var key *serviceKey = (*serviceKey)(nil)
func WithService(parent context.Context, serviceName string) context.Context {
return context.WithValue(parent, key, serviceName)
}
func FromContext(ctx context.Context) string {
value := ctx.Value(key)
if name, ok := value.(string); ok {
return name
}
return ""
}