aboutsummaryrefslogtreecommitdiff
path: root/src/vendor/github.com/rs/xhandler/xhandler_example_test.go
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2016-12-05 08:16:58 +0000
committerFelix Hanley <felix@userspace.com.au>2016-12-05 08:16:58 +0000
commitb049991a46a2f619344bd6e915745703864d0134 (patch)
treeec1d3897a7b69c7c63a3774d4c42dfbb8cb46432 /src/vendor/github.com/rs/xhandler/xhandler_example_test.go
parente1c3d6f7db06d592538f1162b2b6b9f1b6efa330 (diff)
downloadgo-dict2rest-b049991a46a2f619344bd6e915745703864d0134.tar.gz
go-dict2rest-b049991a46a2f619344bd6e915745703864d0134.tar.bz2
Clean up source structure and update vendor versionsHEADmaster
Diffstat (limited to 'src/vendor/github.com/rs/xhandler/xhandler_example_test.go')
-rw-r--r--src/vendor/github.com/rs/xhandler/xhandler_example_test.go67
1 files changed, 0 insertions, 67 deletions
diff --git a/src/vendor/github.com/rs/xhandler/xhandler_example_test.go b/src/vendor/github.com/rs/xhandler/xhandler_example_test.go
deleted file mode 100644
index 9f6f8a5..0000000
--- a/src/vendor/github.com/rs/xhandler/xhandler_example_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package xhandler_test
-
-import (
- "log"
- "net/http"
- "time"
-
- "github.com/rs/xhandler"
- "golang.org/x/net/context"
-)
-
-type key int
-
-const contextKey key = 0
-
-func newContext(ctx context.Context, value string) context.Context {
- return context.WithValue(ctx, contextKey, value)
-}
-
-func fromContext(ctx context.Context) (string, bool) {
- value, ok := ctx.Value(contextKey).(string)
- return value, ok
-}
-
-func ExampleHandle() {
- var xh xhandler.HandlerC
- xh = xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- value, _ := fromContext(ctx)
- w.Write([]byte("Hello " + value))
- })
-
- xh = (func(next xhandler.HandlerC) xhandler.HandlerC {
- return xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- ctx = newContext(ctx, "World")
- next.ServeHTTPC(ctx, w, r)
- })
- })(xh)
-
- ctx := context.Background()
- // Bridge context aware handlers with http.Handler using xhandler.Handle()
- http.Handle("/", xhandler.New(ctx, xh))
-
- if err := http.ListenAndServe(":8080", nil); err != nil {
- log.Fatal(err)
- }
-}
-
-func ExampleHandleTimeout() {
- var xh xhandler.HandlerC
- xh = xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- w.Write([]byte("Hello World"))
- if _, ok := ctx.Deadline(); ok {
- w.Write([]byte(" with deadline"))
- }
- })
-
- // This handler adds a timeout to the handler
- xh = xhandler.TimeoutHandler(5 * time.Second)(xh)
-
- ctx := context.Background()
- // Bridge context aware handlers with http.Handler using xhandler.Handle()
- http.Handle("/", xhandler.New(ctx, xh))
-
- if err := http.ListenAndServe(":8080", nil); err != nil {
- log.Fatal(err)
- }
-}