goProject/trunk/game/common/server_http/handlerMgr.go
2025-01-15 17:36:12 +08:00

38 lines
728 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 server_http
import (
"fmt"
. "common/model"
)
type Handler func(*Context) *ServerResponseObject
var (
// 处理函数集合
handlerMap map[string]Handler
)
func init() {
handlerMap = make(map[string]Handler, 8)
}
// RegisterHandler 详细的注册一个WebAPI处理函数
// pattern:路由地址
// handler:处理函数
// paramInfo:参数列表
func RegisterHandler(pattern string, handler Handler) {
if _, exist := handlerMap[pattern]; exist {
panic(fmt.Errorf("存在重复的webapi注册%s", pattern))
}
// 添加处理对象
handlerMap[pattern] = handler
}
// 获取处理函数
func getHandler(pattern string) (handler Handler, exists bool) {
handler, exists = handlerMap[pattern]
return
}