feat: add pause and resume

This commit is contained in:
langhuihui
2023-06-06 19:25:51 +08:00
parent f4fb7881f7
commit 28a51b9b60
4 changed files with 43 additions and 10 deletions

View File

@@ -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)
// }
// }))
}
}
}