|
1 |
| -// Package netbug provides a http.Handler for executing the various |
2 |
| -// profilers and debug tools in the Go std library. |
| 1 | +// Package netbug provides an http.Handler for executing the various |
| 2 | +// profilers and debug tools in the Go standard library. |
3 | 3 | //
|
4 | 4 | // netbug provides some advantages over the /net/http/pprof and
|
5 | 5 | // /runtime/pprof packages:
|
|
58 | 58 | // }
|
59 | 59 | // }
|
60 | 60 | //
|
61 |
| -// You can then access the index page via GET /myroute/?token=open%20sesame |
| 61 | +// You can then access the index page via: |
| 62 | +// |
| 63 | +// GET /myroute/?token=open%20sesame |
62 | 64 | //
|
63 | 65 | // The package also provides access to the handlers directly, for when
|
64 | 66 | // you want to, say, wrap them in your own logic. Just be sure that
|
65 |
| -// when you use the handlers netbug provides you take care to use |
66 |
| -// `http.StripPrefix` to strip the route you register the handler on. |
| 67 | +// when you use the handlers that netbug provides, you take care to use |
| 68 | +// `http.StripPrefix` to strip the route you registered the handler on. |
67 | 69 | // This is because the handlers' logic expect them to be registered on
|
68 | 70 | // "/".
|
69 | 71 | //
|
|
76 | 78 | // "github.com/e-dard/netbug"
|
77 | 79 | // )
|
78 | 80 | //
|
79 |
| -// func myHandler(h http.Handler) http.Handler { |
| 81 | +// // h is a handler that you wish to wrap around netbug's handler, |
| 82 | +// // allowing you to add your own logic (other types of |
| 83 | +// // authentication for example). |
| 84 | +// func h(h http.Handler) http.Handler { |
80 | 85 | // mh := func(w http.ResponseWriter, r *http.Request) {
|
81 | 86 | // // Some logic here.
|
82 | 87 | // h.ServeHTTP(w, r)
|
|
86 | 91 | //
|
87 | 92 | // func main() {
|
88 | 93 | // r := http.NewServeMux()
|
89 |
| -// rh := http.StripPrefix("/myroute/", netbug.Handler()) |
90 |
| -// r.Handle("/myroute/", myHandler(rh)) |
| 94 | +// |
| 95 | +// // netbug's handler assumes it's registered on "/", so you need |
| 96 | +// // to strip any prefix you actually want to register it on, if |
| 97 | +// // you're not using the netbug.RegisterX functions. |
| 98 | +// nbH := http.StripPrefix("/myroute/", netbug.Handler()) |
| 99 | +// |
| 100 | +// // Wrap the netbug handler in your own, and register the result. |
| 101 | +// r.Handle("/myroute/", h(nbH)) |
91 | 102 | //
|
92 | 103 | // if err := http.ListenAndServe(":8080", r); err != nil {
|
93 | 104 | // log.Fatal(err)
|
|
0 commit comments