55 lines
1006 B
Go
55 lines
1006 B
Go
package krpc
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"text/template"
|
|
)
|
|
|
|
const debugText = `<html>
|
|
<head><title>kRPC Services</title></head>
|
|
<body>
|
|
{{range .}}
|
|
<hr>
|
|
Service {{.Name}}
|
|
<hr>
|
|
<table>
|
|
<tr>
|
|
<th>Method</th><th>Calls</th>
|
|
</tr>
|
|
<tr>
|
|
{{range $name, $mtype := .Method}}
|
|
<tr>
|
|
<td>{{$name}}({{$mtype.ArgType}}, {{$mtype.ReplyType}}) error</td>
|
|
<td>{{$mtype.NumCalls}}
|
|
</tr>
|
|
{{end}}
|
|
</tr>
|
|
</table>
|
|
{{end}}
|
|
</body>`
|
|
|
|
var debug = template.Must(template.New("RPC debug").Parse(debugText))
|
|
|
|
type debugHTTP struct {
|
|
*Server
|
|
}
|
|
|
|
type debugService struct {
|
|
Name string
|
|
Method map[string]*methodType
|
|
}
|
|
|
|
func (s debugHTTP) ServeHTTP(w http.ResponseWriter, r *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
|
|
})
|
|
err := debug.Execute(w, services)
|
|
if err != nil {
|
|
_, _ = fmt.Fprintln(w, "rpc: error executing template:", err.Error())
|
|
}
|
|
}
|