代码拉取完成,页面将自动刷新
package yasrpc
import (
"fmt"
"html/template"
"net/http"
)
const debugText = `<html>
<body>
<title>YasRPC Services</title>
{{range .}}
<hr>
Service {{.Name}}
<hr>
<table>
<th align=center>Method</th>
<th align=center>Calls</th>
{{range $name, $mtype := .Method}}
<tr>
<td align=left font=fixed>{{$name}}({{$mtype.ArgType}}, {{$mtype.ReplyType}}) error</td>
<td align=center>{{$mtype.NumCalls}}</td>
</tr>
{{end}}
</table>
{{end}}
</body>
</html>
`
var debug = template.Must(template.New("RPC debug").Parse(debugText))
type debugHTTP struct {
*Server
}
type debugService struct {
Name string
Method map[string]*methodType
}
// Runs at /debug/yasrpc
func (s debugHTTP) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var services []debugService
s.serviceMap.Range(func(namei, svci interface{}) bool {
svc := svci.(*service)
services = append(services, debugService{
Name: namei.(string),
Method: svc.method,
})
return true
})
if err := debug.Execute(w, services); err != nil {
_, _ = fmt.Fprintln(w, "rpc: error executing template:", err.Error())
}
}
// Runs at /debug/yasrpc
func (s debugHTTP) HandleWeb(ctx *Context) {
var services []debugService
s.serviceMap.Range(func(namei, svci interface{}) bool {
svc := svci.(*service)
services = append(services, debugService{
Name: namei.(string),
Method: svc.method,
})
return true
})
if err := debug.Execute(ctx.Writer, services); err != nil {
_, _ = fmt.Fprintln(ctx.Writer, "rpc: error executing template:", err.Error())
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。