1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +02:00

Inject Namespace into Context

This commit is contained in:
Ben Toogood
2020-04-14 09:14:07 +01:00
parent bf65dc71c7
commit d61d30ef66
5 changed files with 29 additions and 5 deletions

View File

@ -133,3 +133,11 @@ func ContextWithAccount(ctx context.Context, account *Account) (context.Context,
// generate a new context with the MetadataKey set
return metadata.Set(ctx, MetadataKey, string(bytes)), nil
}
// NamespaceFromContext gets the namespace from the context
func NamespaceFromContext(ctx context.Context) string {
if ns, ok := metadata.Get(ctx, NamespaceKey); ok {
return ns
}
return DefaultNamespace
}