Files
utility_go/pkg/websocket/registerer.go
2025-03-24 17:39:09 +08:00

17 lines
376 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 websocket
import "context"
// 定义一个处理方法的类型
type Handler func(ctx context.Context, req any) (err error)
// 路由器的处理映射
var (
handlers = make(map[int]Handler)
)
// 注册方法将某个消息路由器ID和对应的处理方法关联起来
func (s *SocketV1) RegisterRouter(cmd int, handler Handler) {
handlers[cmd] = handler
}