// Package config ... // // Description : WS-Command 相关配置 // // Author : go_developer@163.com<白茶清欢> // // Date : 2021-04-17 2:34 下午 package config const ( // DefaultPushMessageWithError 默认开启异常消息推送 DefaultPushMessageWithError = true // DefaultLogUpData 默认开记录上行数据 DefaultLogUpData = true // DefaultLogDownData 默认开启记录下行数据 DefaultLogDownData = true // DefaultResponseData 默认开启向客户端响应数据 DefaultResponseData = true ) // CommandConfig 指令相关配置 // // Author : go_developer@163.com<白茶清欢> // // Date : 2:36 下午 2021/4/17 type CommandConfig struct { PushMessageWithError bool // 当调度指令时,指令执行错误,是否想客户端推送错误消息 LogUpData bool // 记录上行数据(客户端发送上来的数据) LogDownData bool // 记录响应数据(服务端向客户端响应的数据) ResponseData bool // 是否需要向客户端响应数据 } // SetCommandConfig 设置command配置 type SetCommandConfig func(cc *CommandConfig) // ClosePushCommandErrorMessage 关闭指令执行异常时的消息推送 // // Author : go_developer@163.com<白茶清欢> // // Date : 2:51 下午 2021/4/17 func ClosePushCommandErrorMessage() SetCommandConfig { return func(cc *CommandConfig) { cc.PushMessageWithError = false } } // CloseLogUpData 关闭记录上行数据 // // Author : go_developer@163.com<白茶清欢> // // Date : 7:44 下午 2021/4/18 func CloseLogUpData() SetCommandConfig { return func(cc *CommandConfig) { cc.LogUpData = false } } // CloseLogDownData 关闭记录下行数据 // // Author : go_developer@163.com<白茶清欢> // // Date : 7:45 下午 2021/4/18 func CloseLogDownData() SetCommandConfig { return func(cc *CommandConfig) { cc.LogDownData = false } } // CloseResponseData 关闭向客户端发送响应结果 // // Author : go_developer@163.com<白茶清欢> // // Date : 7:47 下午 2021/4/18 func CloseResponseData() SetCommandConfig { return func(cc *CommandConfig) { cc.ResponseData = false } } // NewCommandConfig 指令的配置 // // Author : go_developer@163.com<白茶清欢> // // Date : 2:39 下午 2021/4/17 func NewCommandConfig(optionFunc ...SetCommandConfig) *CommandConfig { cc := &CommandConfig{ PushMessageWithError: DefaultPushMessageWithError, // 默认推送异常消息 LogUpData: DefaultLogUpData, // 记录上行数据日志 LogDownData: DefaultLogDownData, // 记录下行日志数据 ResponseData: DefaultResponseData, // 默认自动响应数据 } for _, o := range optionFunc { o(cc) } return cc }