Ai
2 Star 3 Fork 0

YashanDB Community/yasrpc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
debug.go 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
zhouyuxin 提交于 2023-06-20 20:28 +08:00 . feat: init web
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())
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yashan_tech/yasrpc.git
git@gitee.com:yashan_tech/yasrpc.git
yashan_tech
yasrpc
yasrpc
master

搜索帮助