1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
8 Some HTML presented at http://machine:port/debug/rpc
9 Lists services, their methods, and some statistics, still rudimentary.
19 const debugText = `<html>
21 <title>Services</title>
27 <th align=center>Method</th><th align=center>Calls</th>
30 <td align=left font=fixed>{{.Name}}({{.Type.ArgType}}, {{.Type.ReplyType}}) error</td>
31 <td align=center>{{.Type.NumCalls}}</td>
39 var debug = template.Must(template.New("RPC debug").Parse(debugText))
41 // If set, print log statements for internal and I/O errors.
44 type debugMethod struct {
49 type methodArray []debugMethod
51 type debugService struct {
57 type serviceArray []debugService
59 func (s serviceArray) Len() int { return len(s) }
60 func (s serviceArray) Less(i, j int) bool { return s[i].Name < s[j].Name }
61 func (s serviceArray) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
63 func (m methodArray) Len() int { return len(m) }
64 func (m methodArray) Less(i, j int) bool { return m[i].Name < m[j].Name }
65 func (m methodArray) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
67 type debugHTTP struct {
72 func (server debugHTTP) ServeHTTP(w http.ResponseWriter, req *http.Request) {
73 // Build a sorted version of the data.
74 var services = make(serviceArray, len(server.serviceMap))
77 for sname, service := range server.serviceMap {
78 services[i] = debugService{service, sname, make(methodArray, len(service.method))}
80 for mname, method := range service.method {
81 services[i].Method[j] = debugMethod{method, mname}
84 sort.Sort(services[i].Method)
89 err := debug.Execute(w, services)
91 fmt.Fprintln(w, "rpc: error executing template:", err.Error())