diff --git a/coolq/api.go b/coolq/api.go index 1794cc6..03225e1 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -2083,7 +2083,7 @@ func (bot *CQBot) CQReloadEventFilter(file string) global.MSG { } // OK 生成成功返回值 -func OK(data interface{}) global.MSG { +func OK(data any) global.MSG { return global.MSG{"data": data, "retcode": 0, "status": "ok"} } diff --git a/coolq/cqcode.go b/coolq/cqcode.go index e93e50c..ab73c5f 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -807,7 +807,7 @@ func (bot *CQBot) ConvertContentMessage(content []global.MSG, sourceType message // 返回 interface{} 存在三种类型 // // message.IMessageElement []message.IMessageElement nil -func (bot *CQBot) ToElement(t string, d map[string]string, sourceType message.SourceType) (m interface{}, err error) { +func (bot *CQBot) ToElement(t string, d map[string]string, sourceType message.SourceType) (m any, err error) { switch t { case "text": if base.SplitURL { diff --git a/coolq/event.go b/coolq/event.go index 4bd8372..e54a40e 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -21,7 +21,7 @@ import ( ) // ToFormattedMessage 将给定[]message.IMessageElement转换为通过coolq.SetMessageFormat所定义的消息上报格式 -func ToFormattedMessage(e []message.IMessageElement, source message.Source) (r interface{}) { +func ToFormattedMessage(e []message.IMessageElement, source message.Source) (r any) { if base.PostFormat == "string" { r = toStringMessage(e, source) } else if base.PostFormat == "array" { diff --git a/db/leveldb/reader.go b/db/leveldb/reader.go index e891036..fef6ebd 100644 --- a/db/leveldb/reader.go +++ b/db/leveldb/reader.go @@ -84,7 +84,7 @@ func (r *reader) arrayMsg() []global.MSG { return msgs } -func (r *reader) obj() interface{} { +func (r *reader) obj() any { switch coder := r.coder(); coder { case coderNil: return nil diff --git a/db/leveldb/writer.go b/db/leveldb/writer.go index 6067ca1..a8acba7 100644 --- a/db/leveldb/writer.go +++ b/db/leveldb/writer.go @@ -96,7 +96,7 @@ func (w *writer) arrayMsg(a []global.MSG) { } } -func (w *writer) obj(o interface{}) { +func (w *writer) obj(o any) { switch x := o.(type) { case nil: w.nil() diff --git a/global/log_hook.go b/global/log_hook.go index 44f4f1d..df3084b 100644 --- a/global/log_hook.go +++ b/global/log_hook.go @@ -108,7 +108,7 @@ func (hook *LocalHook) SetPath(path string) { } // NewLocalHook 初始化本地日志钩子实现 -func NewLocalHook(args interface{}, consoleFormatter, fileFormatter logrus.Formatter, levels ...logrus.Level) *LocalHook { +func NewLocalHook(args any, consoleFormatter, fileFormatter logrus.Formatter, levels ...logrus.Level) *LocalHook { hook := &LocalHook{ lock: new(sync.Mutex), } diff --git a/global/param.go b/global/param.go index 44225bd..0b24580 100644 --- a/global/param.go +++ b/global/param.go @@ -8,7 +8,7 @@ import ( ) // MSG 消息Map -type MSG = map[string]interface{} +type MSG = map[string]any // VersionNameCompare 检查版本名是否需要更新, 仅适用于 go-cqhttp 的版本命名规则 // diff --git a/internal/param/param.go b/internal/param/param.go index 19da7fc..8e763e1 100644 --- a/internal/param/param.go +++ b/internal/param/param.go @@ -19,7 +19,7 @@ import ( // type gjson.True or gjson.False // // type string "true","yes","1" or "false","no","0" (case insensitive) -func EnsureBool(p interface{}, defaultVal bool) bool { +func EnsureBool(p any, defaultVal bool) bool { var str string if b, ok := p.(bool); ok { return b diff --git a/server/middlewares.go b/server/middlewares.go index 7230248..f783e0f 100644 --- a/server/middlewares.go +++ b/server/middlewares.go @@ -50,7 +50,7 @@ func longPolling(bot *coolq.CQBot, maxSize int) api.Handler { return nil } var ( - ch = make(chan []interface{}) + ch = make(chan []any) timeout = time.Duration(p.Get("timeout").Int()) * time.Second ) go func() { @@ -63,7 +63,7 @@ func longPolling(bot *coolq.CQBot, maxSize int) api.Handler { if limit <= 0 || queue.Len() < limit { limit = queue.Len() } - ret := make([]interface{}, limit) + ret := make([]any, limit) elem := queue.Front() for i := 0; i < limit; i++ { ret[i] = elem.Value @@ -81,7 +81,7 @@ func longPolling(bot *coolq.CQBot, maxSize int) api.Handler { if timeout != 0 { select { case <-time.After(timeout): - return coolq.OK([]interface{}{}) + return coolq.OK([]any{}) case ret := <-ch: return coolq.OK(ret) }