diff --git a/plugins/register.go b/plugins/register.go index 240e826..7e5468b 100644 --- a/plugins/register.go +++ b/plugins/register.go @@ -12,6 +12,7 @@ import ( "git.zhangdeman.cn/gateway/core/define" "git.zhangdeman.cn/gateway/core/plugins/abstract" "git.zhangdeman.cn/zhangdeman/trace" + "strings" "sync" "time" ) @@ -81,12 +82,15 @@ func NewPluginResult(rc *define.RequestContext) *define.PluginResult { // Author : go_developer@163.com<白茶清欢> // // Date : 18:07 2024/11/13 -func Dispatch(rc *define.RequestContext, pluginIDList []string) (map[string]abstract.IPlugin, error) { +func Dispatch(rc *define.RequestContext, pluginIDList []string) error { l := &sync.RWMutex{} errList := []string{} + wg := &sync.WaitGroup{} for _, itemPluginID := range pluginIDList { + wg.Add(1) go func(pluginID string) { defer func() { + wg.Done() if r := recover(); r != nil { l.Lock() errList = append(errList, r.(error).Error()) @@ -114,9 +118,14 @@ func Dispatch(rc *define.RequestContext, pluginIDList []string) (map[string]abst l.Unlock() return } + rc.SetPluginResult(pluginResult) }(itemPluginID) } - return nil, nil + wg.Wait() + if len(errList) > 0 { + return errors.New(strings.Join(errList, "|")) + } + return nil } // InitDefault 初始化注册默认的插件