MCPcopy Index your code
hub / github.com/Monibuca/engine / registerHandler

Method registerHandler

plugin.go:144–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142}
143
144func (opt *Plugin) registerHandler() {
145 t := reflect.TypeOf(opt.Config)
146 v := reflect.ValueOf(opt.Config)
147 // 注册http响应
148 for i, j := 0, t.NumMethod(); i < j; i++ {
149 name := t.Method(i).Name
150 if name == "ServeHTTP" {
151 continue
152 }
153 switch handler := v.Method(i).Interface().(type) {
154 case func(http.ResponseWriter, *http.Request):
155 patten := strings.ToLower(strings.ReplaceAll(name, "_", "/"))
156 opt.handle(patten, http.HandlerFunc(handler))
157 }
158 }
159 if rootHandler, ok := opt.Config.(http.Handler); ok {
160 opt.handle("/", rootHandler)
161 }
162}
163
164func (opt *Plugin) settingPath() string {
165 return filepath.Join(SettingDir, strings.ToLower(opt.Name)+".yaml")

Callers 1

assignMethod · 0.95

Calls 2

handleMethod · 0.95
InterfaceMethod · 0.80

Tested by

no test coverage detected