Files
tasks/common/rpc/interceptor/namespace.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

64 lines
1.8 KiB
Go

package interceptor
import (
"go.temporal.io/api/serviceerror"
"go.temporal.io/api/workflowservice/v1"
"github.com/hanzoai/tasks/common/namespace"
)
// gRPC method request must implement either NamespaceNameGetter or NamespaceIDGetter
// for namespace specific metrics to be reported properly
type (
NamespaceNameGetter interface {
GetNamespace() string
}
NamespaceIDGetter interface {
GetNamespaceId() string
}
)
// MustGetNamespaceName returns request namespace name
// or EmptyName if there's error when retrieving namespace name,
// e.g. unable to find namespace
func MustGetNamespaceName(
namespaceRegistry namespace.Registry,
req any,
) namespace.Name {
namespaceName, err := GetNamespaceName(namespaceRegistry, req)
if err != nil {
return namespace.EmptyName
}
return namespaceName
}
func GetNamespaceName(
namespaceRegistry namespace.Registry,
req any,
) (namespace.Name, error) {
switch request := req.(type) {
case *workflowservice.RegisterNamespaceRequest:
// For namespace registration requests, we don't expect to find namespace so skip checking caches
// to avoid caching a NotFound error from persistence readthrough
return namespace.Name(request.GetNamespace()), nil
case NamespaceNameGetter:
namespaceName := namespace.Name(request.GetNamespace())
_, err := namespaceRegistry.GetNamespace(namespaceName)
if err != nil {
return namespace.EmptyName, err
}
return namespaceName, nil
case NamespaceIDGetter:
namespaceID := namespace.ID(request.GetNamespaceId())
namespaceName, err := namespaceRegistry.GetNamespaceName(namespaceID)
if err != nil {
return namespace.EmptyName, err
}
return namespaceName, nil
default:
return namespace.EmptyName, serviceerror.NewInternalf("unable to extract namespace info from request of type %T", req)
}
}