mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-05 08:36:56 +08:00
feat: add pause and resume
This commit is contained in:
27
plugin.go
27
plugin.go
@@ -189,12 +189,29 @@ func (opt *Plugin) registerHandler() {
|
||||
// 注册http响应
|
||||
for i, j := 0, t.NumMethod(); i < j; i++ {
|
||||
name := t.Method(i).Name
|
||||
if handler, ok := v.Method(i).Interface().(func(http.ResponseWriter, *http.Request)); ok {
|
||||
patten := "/"
|
||||
if name != "ServeHTTP" {
|
||||
patten = strings.ToLower(strings.ReplaceAll(name, "_", "/"))
|
||||
}
|
||||
patten := "/"
|
||||
if name != "ServeHTTP" {
|
||||
patten = strings.ToLower(strings.ReplaceAll(name, "_", "/"))
|
||||
}
|
||||
switch handler := v.Method(i).Interface().(type) {
|
||||
case func(http.ResponseWriter, *http.Request):
|
||||
opt.handle(patten, http.HandlerFunc(handler))
|
||||
// case func(*http.Request) (int, string, any):
|
||||
// opt.handle(patten, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
// code, msg, data := handler(r)
|
||||
// switch returnMode {
|
||||
// case "json":
|
||||
// rw.Header().Set("Content-Type", "application/json")
|
||||
// rw.WriteHeader(http.StatusOK)
|
||||
// json.NewEncoder(rw).Encode(map[string]interface{}{
|
||||
// "code": code,
|
||||
// "msg": msg,
|
||||
// "data": data,
|
||||
// })
|
||||
// default:
|
||||
// http.Error(rw, msg, code)
|
||||
// }
|
||||
// }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user