Documentation
¶
Overview ¶
Package mt provides generic multi-tenant tools.
Index ¶
- func CloneCtx(ctx context.Context) context.Context
- func ExpandConfigReader(yamlPath string) (io.Reader, error)
- func ExtractTID(ctx context.Context) string
- func InjectTID(ctx context.Context, tenantID string) context.Context
- func InjectTenantFromObj(ctx context.Context, v any) context.Context
- func SetDefTenant(tenantID string)
- type ConfigMgr
- type ISDK
- type ISDKE
- type InitFn
- type InitFnE
- type InitFnWMet
- type MockISDK
- type MockISDKE
- type MockISDKEMockRecorder
- type MockISDKMockRecorder
- type SDKMgr
- type SDKMgrE
- type SDKMgrWMet
- type TenantRepl
- type TplRenderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneCtx ¶
CloneCtx creates a new context from parent with tenant ID and OpenTelemetry values preserved. Cancellation is not inherited; metadata is copied.
func ExpandConfigReader ¶
ExpandConfigReader merges defaults into per-tenant configs and returns an io.Reader. YAML must have a "default" section. Other sections inherit from default and can override. Placeholders ${tenant} are replaced with the tenant ID.
func ExtractTID ¶
ExtractTID returns tenant ID from context, or defaultTID if not found.
func InjectTenantFromObj ¶
InjectTenantFromObj extracts tenant ID from v if it implements tenantIDGetter, then stores it in a new context returned.
func SetDefTenant ¶
func SetDefTenant(tenantID string)
SetDefTenant sets the default tenant ID. Must be called once.
Types ¶
type ConfigMgr ¶
type ConfigMgr[T any] struct { // contains filtered or unexported fields }
ConfigMgr holds per-tenant configs with a fallback default.
func NewConfigMgr ¶
NewConfigMgr creates a new manager with copied tenant configs and a default.
type ISDK ¶
ISDK is the interface for SDK managers returning T.
type MockISDK ¶
type MockISDK[T any] struct { // contains filtered or unexported fields }
MockISDK is a mock of ISDK interface.
func NewISDKMock ¶
NewISDKMock creates a mock for ISDK[T] (test helper).
func NewMockISDK ¶
func NewMockISDK[T any](ctrl *gomock.Controller) *MockISDK[T]
NewMockISDK creates a new mock instance.
func (*MockISDK[T]) EXPECT ¶
func (m *MockISDK[T]) EXPECT() *MockISDKMockRecorder[T]
EXPECT returns an object that allows expected use.
type MockISDKE ¶
type MockISDKE[T any] struct { // contains filtered or unexported fields }
MockISDKE is a mock of ISDKE interface.
func NewISDKEMock ¶
NewISDKEMock creates a mock for ISDKE[T] (test helper).
func NewMockISDKE ¶
func NewMockISDKE[T any](ctrl *gomock.Controller) *MockISDKE[T]
NewMockISDKE creates a new mock instance.
func (*MockISDKE[T]) EXPECT ¶
func (m *MockISDKE[T]) EXPECT() *MockISDKEMockRecorder[T]
EXPECT returns an object that allows expected use.
func (*MockISDKE[T]) IsCentralized ¶
IsCentralized mocks base method.
type MockISDKEMockRecorder ¶
type MockISDKEMockRecorder[T any] struct { // contains filtered or unexported fields }
MockISDKEMockRecorder is the mock recorder for MockISDKE.
func (*MockISDKEMockRecorder[T]) Get ¶
func (mr *MockISDKEMockRecorder[T]) Get(ctx any) *gomock.Call
Get indicates an expected call of Get.
func (*MockISDKEMockRecorder[T]) IsCentralized ¶
func (mr *MockISDKEMockRecorder[T]) IsCentralized() *gomock.Call
IsCentralized indicates an expected call of IsCentralized.
type MockISDKMockRecorder ¶
type MockISDKMockRecorder[T any] struct { // contains filtered or unexported fields }
MockISDKMockRecorder is the mock recorder for MockISDK.
type SDKMgrE ¶
SDKMgrE manages per-tenant SDK instances with error handling.
func (*SDKMgrE[S, C]) IsCentralized ¶
type SDKMgrWMet ¶
SDKMgrWMet manages per-tenant SDK instances with metrics.
func (*SDKMgrWMet[S, C, M]) Get ¶
func (s *SDKMgrWMet[S, C, M]) Get(ctx context.Context) S
func (*SDKMgrWMet[S, C, M]) Map ¶
func (m *SDKMgrWMet[S, C, M]) Map(f func(string, S))
type TenantRepl ¶
type TenantRepl struct {
// contains filtered or unexported fields
}
TenantRepl is a regex-based tenant ID replacer.
func NewTenantRepl ¶
func NewTenantRepl(pairs map[string]string) (*TenantRepl, error)
NewTenantRepl creates a replacer from pattern→replacement pairs.
func (*TenantRepl) Replace ¶
func (r *TenantRepl) Replace(input string) string
Replace returns the first matching replacement for input, or input if no match.
type TplRenderer ¶
type TplRenderer struct {
// contains filtered or unexported fields
}
TplRenderer implements echo template rendering with per-tenant templates.
func NewTplRenderer ¶
func NewTplRenderer(basePath string, tenantReplacements map[string]string) (*TplRenderer, error)
NewTplRenderer loads templates from tenant subdirectories of basePath. tenantReplacements are used to map tenant IDs to template sets.