Files
tavern/core/group.go

56 lines
1.2 KiB
Go
Raw Normal View History

2023-05-24 16:10:00 +09:00
package core
import (
2023-07-25 18:11:02 +09:00
"net/http"
"reflect"
2023-05-24 16:10:00 +09:00
2023-07-25 18:11:02 +09:00
"repositories.action2quare.com/ayo/gocommon/wshandler"
2023-05-24 16:10:00 +09:00
)
2023-07-25 18:11:02 +09:00
var groupTypes map[string]reflect.Type
func groupTypeContainer() map[string]reflect.Type {
if groupTypes == nil {
groupTypes = make(map[string]reflect.Type)
}
return groupTypes
}
type apiFuncType func(http.ResponseWriter, *http.Request)
type apiFuncsContainer struct {
normfuncs map[string]apiFuncType
funcs map[string][]apiFuncType
}
func (afc *apiFuncsContainer) registApiFunction(name string, f apiFuncType) {
afc.funcs[name] = append(afc.funcs[name], f)
}
func (afc *apiFuncsContainer) normalize() {
for k, v := range afc.funcs {
if len(v) == 1 {
afc.normfuncs[k] = v[0]
} else {
afc.normfuncs[k] = func(w http.ResponseWriter, r *http.Request) {
for _, f := range v {
f(w, r)
}
}
}
}
afc.funcs = nil
}
func (afc *apiFuncsContainer) call(fn string, w http.ResponseWriter, r *http.Request) {
f := afc.normfuncs[fn]
if f != nil {
f(w, r)
}
2023-05-24 16:10:00 +09:00
}
2023-07-25 18:11:02 +09:00
type configDocument map[string]any
2023-05-24 16:10:00 +09:00
type group interface {
2023-07-25 18:11:02 +09:00
Initialize(*subTavern, configDocument) error
ClientMessageReceved(*wshandler.Sender, wshandler.WebSocketMessageType, any)
2023-05-24 16:10:00 +09:00
}