mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-05 08:36:56 +08:00
feat: reflect ServeHTTP now can use parent
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user