summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Buberel <[email protected]>2015-05-25 06:57:43 -0700
committerJason Buberel <[email protected]>2015-05-25 14:24:11 -0700
commitf9f629a1d082960e5d1747f33c2b378612615fea (patch)
tree21d5e6305da1ecf44dadd9ab2e1c2bb6e12f4aea
parenta6eef0c3a9a158ce0fc790d13fadb69186a36cb5 (diff)
Provide an example on how to debug a web app.
Update README.md Removing extra line.
-rw-r--r--README.md27
1 files changed, 27 insertions, 0 deletions
diff --git a/README.md b/README.md
index c0e90bc..cfc23e6 100644
--- a/README.md
+++ b/README.md
@@ -65,6 +65,33 @@ spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2)
spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
```
+## Debugging a Web Application Example
+
+Here is an example of how you can use `spew.Sdump()` to help debug a web application. Please be sure to wrap your output using the `html.EscapeString()` function for safety reasons. You should also only use this debugging technique in a development environment, never in production.
+
+```Go
+package main
+
+import (
+ "fmt"
+ "html"
+ "net/http"
+
+ "github.com/davecgh/go-spew/spew"
+)
+
+func handler(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/html")
+ fmt.Fprintf(w, "Hi there, %s!", r.URL.Path[1:])
+ fmt.Fprintf(w, "<!--\n" + html.EscapeString(spew.Sdump(w)) + "\n-->")
+}
+
+func main() {
+ http.HandleFunc("/", handler)
+ http.ListenAndServe(":8080", nil)
+}
+```
+
## Sample Dump Output
```