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 serviceArray
75 server
.serviceMap
.Range(func(snamei
, svci
interface{}) bool {
76 svc
:= svci
.(*service
)
77 ds
:= debugService
{svc
, snamei
.(string), make(methodArray
, 0, len(svc
.method
))}
78 for mname
, method
:= range svc
.method
{
79 ds
.Method
= append(ds
.Method
, debugMethod
{method
, mname
})
82 services
= append(services
, ds
)
86 err
:= debug
.Execute(w
, services
)
88 fmt
.Fprintln(w
, "rpc: error executing template:", err
.Error())