1 Star 0 Fork 0

玟兵 / gin-partner

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
model_common.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
玟兵 提交于 2024-05-07 19:41 . 初始化
package partner
import "github.com/gin-gonic/gin"
type CommonModel struct {
name string
allGetHandlers map[string][]gin.HandlerFunc
allPostHandlers map[string][]gin.HandlerFunc
}
var _ Model = (*CommonModel)(nil)
func NewCommonModel(name string) *CommonModel {
return &CommonModel{
name: name,
allGetHandlers: make(map[string][]gin.HandlerFunc),
allPostHandlers: make(map[string][]gin.HandlerFunc),
}
}
func (m *CommonModel) Name() string {
return m.name
}
func (m *CommonModel) GetHandlers() map[string][]gin.HandlerFunc {
return m.allGetHandlers
}
func (m *CommonModel) PostHandlers() map[string][]gin.HandlerFunc {
return m.allPostHandlers
}
func (m *CommonModel) SetGetHandlers(action string, handles ...gin.HandlerFunc) {
m.allGetHandlers[action] = handles
}
func (m *CommonModel) UseGetMiddlewares(action string, handles ...gin.HandlerFunc) {
m.allGetHandlers[action] = append(m.allGetHandlers[action], handles...)
l := len(handles)
copy(m.allGetHandlers[action][l:], m.allGetHandlers[action])
for i := 0; i < l; i++ {
m.allGetHandlers[action][i] = handles[i]
}
}
func (m *CommonModel) ClearGetHandlers(action string) {
delete(m.allGetHandlers, action)
}
func (m *CommonModel) SetPostHandlers(action string, handles ...gin.HandlerFunc) {
m.allPostHandlers[action] = handles
}
func (m *CommonModel) UsePostMiddlewares(action string, handles ...gin.HandlerFunc) {
m.allPostHandlers[action] = append(m.allPostHandlers[action], handles...)
l := len(handles)
copy(m.allPostHandlers[action][l:], m.allPostHandlers[action])
for i := 0; i < l; i++ {
m.allPostHandlers[action][i] = handles[i]
}
}
func (m *CommonModel) ClearPostHandlers(action string) {
delete(m.allPostHandlers, action)
}
Go
1
https://gitee.com/binny_w/gin-partner.git
git@gitee.com:binny_w/gin-partner.git
binny_w
gin-partner
gin-partner
v0.0.4

搜索帮助