[#91] Add support namespaces
Signed-off-by: Roman Loginov <r.loginov@yadro.com>
This commit is contained in:
parent
dc8d0d4ab3
commit
a375af7d98
12 changed files with 236 additions and 37 deletions
26
internal/handler/middleware/util.go
Normal file
26
internal/handler/middleware/util.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// keyWrapper is wrapper for context keys.
|
||||
type keyWrapper string
|
||||
|
||||
const nsKey = keyWrapper("namespace")
|
||||
|
||||
// GetNamespace extract namespace from context.
|
||||
func GetNamespace(ctx context.Context) (string, error) {
|
||||
ns, ok := ctx.Value(nsKey).(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't get namespace from context")
|
||||
}
|
||||
|
||||
return ns, nil
|
||||
}
|
||||
|
||||
// SetNamespace sets namespace in the context.
|
||||
func SetNamespace(ctx context.Context, ns string) context.Context {
|
||||
return context.WithValue(ctx, nsKey, ns)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue