Files
tyapi-server/internal/domains/api/services/processors/invoke.go
2026-06-20 17:28:24 +08:00

33 lines
957 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package processors
import (
"context"
"fmt"
)
// ProcessorRegistry 已注册处理器查询(由 CombService 实现)
type ProcessorRegistry interface {
GetProcessor(apiCode string) (ProcessorFunc, bool)
}
// InvokeRegisteredProcessor 通过注册表调用处理器(含白名单包装),聚合处理器内部转接应使用此方法。
func InvokeRegisteredProcessor(
ctx context.Context,
apiCode string,
params []byte,
deps *ProcessorDependencies,
) ([]byte, error) {
if deps == nil || deps.CombService == nil {
return nil, fmt.Errorf("CombService 未配置,无法调用处理器: %s", apiCode)
}
registry, ok := deps.CombService.(ProcessorRegistry)
if !ok {
return nil, fmt.Errorf("CombService 不支持 GetProcessor无法调用处理器: %s", apiCode)
}
processor, exists := registry.GetProcessor(apiCode)
if !exists {
return nil, fmt.Errorf("未找到处理器: %s", apiCode)
}
return processor(ctx, params, deps)
}