ICommand增加配置方法,支持覆盖全局配置
This commit is contained in:
29
construct.go
29
construct.go
@ -11,6 +11,10 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/go-developer/websocket/message"
|
||||
|
||||
"github.com/go-developer/websocket/config"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/go-developer/websocket/storage"
|
||||
@ -154,10 +158,31 @@ func dispatchCommand(ctx *context.WSContext, data []byte) error {
|
||||
}
|
||||
|
||||
cmd := gjson.Get(string(data), "command").String()
|
||||
if _, exist := commandTable[ctx.Flag][cmd]; !exist {
|
||||
var (
|
||||
exist bool
|
||||
cmdInstance abstract.ICommand
|
||||
cmdConfig *config.CommandConfig
|
||||
err error
|
||||
)
|
||||
if cmdInstance, exist = commandTable[ctx.Flag][cmd]; !exist {
|
||||
return errors.WithStack(errors.New("【" + ctx.Flag + "】长连接模块未注册【" + cmd + "】指令"))
|
||||
}
|
||||
return commandTable[ctx.Flag][cmd].Execute(ctx, data)
|
||||
optionList := cmdInstance.GetConfigOption()
|
||||
if nil == optionList {
|
||||
optionList = make([]config.SetCommandConfig, 0)
|
||||
}
|
||||
cmdConfig = config.NewCommandConfig(optionList...)
|
||||
if err = cmdInstance.Execute(ctx, data); nil != err {
|
||||
if cmdConfig.PushMessageWithError {
|
||||
_ = message.Response(ctx, map[string]interface{}{
|
||||
"command": cmd,
|
||||
"message": err.Error(),
|
||||
"success": false,
|
||||
})
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func run() {
|
||||
|
Reference in New Issue
Block a user