feat: reflect ServeHTTP now can use parent

This commit is contained in:
langhuihui
2023-12-15 18:10:10 +08:00
parent b486af8484
commit 5e3008f00b

View File

@@ -147,15 +147,18 @@ func (opt *Plugin) registerHandler() {
// 注册http响应
for i, j := 0, t.NumMethod(); i < j; i++ {
name := t.Method(i).Name
patten := "/"
if name != "ServeHTTP" {
patten = strings.ToLower(strings.ReplaceAll(name, "_", "/"))
if name == "ServeHTTP" {
continue
}
switch handler := v.Method(i).Interface().(type) {
case func(http.ResponseWriter, *http.Request):
patten := strings.ToLower(strings.ReplaceAll(name, "_", "/"))
opt.handle(patten, http.HandlerFunc(handler))
}
}
if rootHandler, ok := opt.Config.(http.Handler); ok {
opt.handle("/", rootHandler)
}
}
func (opt *Plugin) settingPath() string {