whcompat

package
v1.0.0-...-3f30213 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 2 Imported by: 25

Documentation

Overview

Package whcompat provides webhelp compatibility across different Go releases.

The webhelp suite depends heavily on Go 1.7 style http.Request contexts, which aren't available in earlier Go releases. This package backports all of the functionality in a forwards-compatible way. You can use this package to get the desired behavior for all Go releases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseNotify

func CloseNotify(h http.Handler) http.Handler

CloseNotify causes a handler to have its request.Context() canceled the second the client TCP connection goes away by hooking the http.CloseNotifier logic into the context. Prior to Go 1.8, this costs an extra goroutine in a read loop. Go 1.8 and on, this behavior happens automatically with or without this wrapper.

func Context

func Context(r *http.Request) context.Context

Context is a light wrapper around the behavior of Go 1.7's (*http.Request).Context method, except this version works with earlier Go releases, too. In Go 1.7 and on, this simply calls r.Context(). See the note for WithContext for how this works on previous Go releases. If building with the appengine tag, when needed, fresh contexts will be generated with appengine.NewContext().

func DoneNotify

func DoneNotify(h http.Handler) http.Handler

DoneNotify cancels request contexts when the http.Handler returns in Go releases prior to Go 1.7. In Go 1.7 and forward, this is a no-op. You get this behavior for free if you use whlog.ListenAndServe.

func WithContext

func WithContext(r *http.Request, ctx context.Context) *http.Request

WithContext is a light wrapper around the behavior of Go 1.7's (*http.Request).WithContext method, except this version works with earlier Go releases, too. IMPORTANT CAVEAT: to get this to work for Go 1.6 and earlier, a few tricks are pulled, such as expecting the returned r.URL to never change what object it points to, and a finalizer is set on the returned request.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL