mirror of
https://github.com/geektutu/7days-golang.git
synced 2024-04-21 12:32:11 +00:00
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package geerpc
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"net/http"
|
|
)
|
|
|
|
const debugText = `<html>
|
|
<body>
|
|
<title>GeeRPC 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/geerpc
|
|
func (server debugHTTP) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
// Build a sorted version of the data.
|
|
var services []debugService
|
|
server.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())
|
|
}
|
|
}
|