Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from rs/xhandler/restore_from_ctx
Restore various FromContext functions
- Loading branch information
Showing
5 changed files
with
53 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// +build go1.7 | ||
|
||
package xhandler | ||
|
||
import ( | ||
"net/http" | ||
|
||
"context" | ||
) | ||
|
||
|
||
// New creates a conventional http.Handler injecting the provided root | ||
// context to sub handlers. This handler is used as a bridge between conventional | ||
// http.Handler and context aware handlers. | ||
func New(ctx context.Context, h HandlerC) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
h.ServeHTTPC(ctx, w, r.WithContext(ctx)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// +build !go1.7 | ||
|
||
package xhandler | ||
|
||
import ( | ||
"net/http" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
|
||
// New creates a conventional http.Handler injecting the provided root | ||
// context to sub handlers. This handler is used as a bridge between conventional | ||
// http.Handler and context aware handlers. | ||
func New(ctx context.Context, h HandlerC) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
h.ServeHTTPC(ctx, w, r) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters