Skip to content

Commit 0e63e8e

Browse files
committed
documentation
1 parent 1188752 commit 0e63e8e

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
func main() {
3434
r := http.NewServeMux()
35-
rdb.RegisterHandler("/myroute/", r)
35+
netbug.RegisterHandler("/myroute/", r)
3636
if err := http.ListenAndServe(":8080", r); err != nil {
3737
log.Fatal(err)
3838
}
@@ -57,7 +57,7 @@ import (
5757

5858
func main() {
5959
r := http.NewServeMux()
60-
rdb.RegisterAuthHandler("password", "/myroute/", r)
60+
netbug.RegisterAuthHandler("password", "/myroute/", r)
6161
if err := http.ListenAndServe(":8080", r); err != nil {
6262
log.Fatal(err)
6363
}

doc.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
33
//
44
// netbug provides some advantages over the /net/http/pprof and
55
// /runtime/pprof packages:
@@ -58,12 +58,14 @@
5858
// }
5959
// }
6060
//
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
6264
//
6365
// The package also provides access to the handlers directly, for when
6466
// 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.
6769
// This is because the handlers' logic expect them to be registered on
6870
// "/".
6971
//
@@ -76,7 +78,10 @@
7678
// "github.com/e-dard/netbug"
7779
// )
7880
//
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 {
8085
// mh := func(w http.ResponseWriter, r *http.Request) {
8186
// // Some logic here.
8287
// h.ServeHTTP(w, r)
@@ -86,8 +91,14 @@
8691
//
8792
// func main() {
8893
// 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))
91102
//
92103
// if err := http.ListenAndServe(":8080", r); err != nil {
93104
// log.Fatal(err)

0 commit comments

Comments
 (0)