frostfs-http-gw/internal/handler/middleware/util.go
Roman Loginov a375af7d98 [#91] Add support namespaces
Signed-off-by: Roman Loginov <r.loginov@yadro.com>
2023-12-01 10:12:55 +00:00

26 lines
553 B
Go

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)
}