From 5e3008f00bebc2f5e15c4f5651e9b54d0b881dfc Mon Sep 17 00:00:00 2001 From: langhuihui <178529795@qq.com> Date: Fri, 15 Dec 2023 18:10:10 +0800 Subject: [PATCH] feat: reflect ServeHTTP now can use parent --- plugin.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugin.go b/plugin.go index d6807cf..7a11651 100644 --- a/plugin.go +++ b/plugin.go @@ -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 {