11package context
22
33import (
4+ "context"
45 "errors"
56 "net"
67 "net/http"
@@ -68,7 +69,7 @@ func RemoteIP(r *http.Request) string {
6869// is available at "http.request". Other common attributes are available under
6970// the prefix "http.request.". If a request is already present on the context,
7071// this method will panic.
71- func WithRequest (ctx Context , r * http.Request ) Context {
72+ func WithRequest (ctx context. Context , r * http.Request ) context. Context {
7273 if ctx .Value ("http.request" ) != nil {
7374 // NOTE(stevvooe): This needs to be considered a programming error. It
7475 // is unlikely that we'd want to have more than one request in
@@ -87,7 +88,7 @@ func WithRequest(ctx Context, r *http.Request) Context {
8788// GetRequest returns the http request in the given context. Returns
8889// ErrNoRequestContext if the context does not have an http request associated
8990// with it.
90- func GetRequest (ctx Context ) (* http.Request , error ) {
91+ func GetRequest (ctx context. Context ) (* http.Request , error ) {
9192 if r , ok := ctx .Value ("http.request" ).(* http.Request ); r != nil && ok {
9293 return r , nil
9394 }
@@ -96,13 +97,13 @@ func GetRequest(ctx Context) (*http.Request, error) {
9697
9798// GetRequestID attempts to resolve the current request id, if possible. An
9899// error is return if it is not available on the context.
99- func GetRequestID (ctx Context ) string {
100+ func GetRequestID (ctx context. Context ) string {
100101 return GetStringValue (ctx , "http.request.id" )
101102}
102103
103104// WithResponseWriter returns a new context and response writer that makes
104105// interesting response statistics available within the context.
105- func WithResponseWriter (ctx Context , w http.ResponseWriter ) (Context , http.ResponseWriter ) {
106+ func WithResponseWriter (ctx context. Context , w http.ResponseWriter ) (context. Context , http.ResponseWriter ) {
106107 if closeNotifier , ok := w .(http.CloseNotifier ); ok {
107108 irwCN := & instrumentedResponseWriterCN {
108109 instrumentedResponseWriter : instrumentedResponseWriter {
@@ -125,7 +126,7 @@ func WithResponseWriter(ctx Context, w http.ResponseWriter) (Context, http.Respo
125126// GetResponseWriter returns the http.ResponseWriter from the provided
126127// context. If not present, ErrNoResponseWriterContext is returned. The
127128// returned instance provides instrumentation in the context.
128- func GetResponseWriter (ctx Context ) (http.ResponseWriter , error ) {
129+ func GetResponseWriter (ctx context. Context ) (http.ResponseWriter , error ) {
129130 v := ctx .Value ("http.response" )
130131
131132 rw , ok := v .(http.ResponseWriter )
@@ -145,7 +146,7 @@ var getVarsFromRequest = mux.Vars
145146// example, if looking for the variable "name", it can be accessed as
146147// "vars.name". Implementations that are accessing values need not know that
147148// the underlying context is implemented with gorilla/mux vars.
148- func WithVars (ctx Context , r * http.Request ) Context {
149+ func WithVars (ctx context. Context , r * http.Request ) context. Context {
149150 return & muxVarsContext {
150151 Context : ctx ,
151152 vars : getVarsFromRequest (r ),
@@ -155,7 +156,7 @@ func WithVars(ctx Context, r *http.Request) Context {
155156// GetRequestLogger returns a logger that contains fields from the request in
156157// the current context. If the request is not available in the context, no
157158// fields will display. Request loggers can safely be pushed onto the context.
158- func GetRequestLogger (ctx Context ) Logger {
159+ func GetRequestLogger (ctx context. Context ) Logger {
159160 return GetLogger (ctx ,
160161 "http.request.id" ,
161162 "http.request.method" ,
@@ -171,7 +172,7 @@ func GetRequestLogger(ctx Context) Logger {
171172// Because the values are read at call time, pushing a logger returned from
172173// this function on the context will lead to missing or invalid data. Only
173174// call this at the end of a request, after the response has been written.
174- func GetResponseLogger (ctx Context ) Logger {
175+ func GetResponseLogger (ctx context. Context ) Logger {
175176 l := getLogrusLogger (ctx ,
176177 "http.response.written" ,
177178 "http.response.status" ,
@@ -188,7 +189,7 @@ func GetResponseLogger(ctx Context) Logger {
188189
189190// httpRequestContext makes information about a request available to context.
190191type httpRequestContext struct {
191- Context
192+ context. Context
192193
193194 startedAt time.Time
194195 id string
@@ -247,7 +248,7 @@ fallback:
247248}
248249
249250type muxVarsContext struct {
250- Context
251+ context. Context
251252 vars map [string ]string
252253}
253254
@@ -282,7 +283,7 @@ type instrumentedResponseWriterCN struct {
282283// implemented by the parent ResponseWriter.
283284type instrumentedResponseWriter struct {
284285 http.ResponseWriter
285- Context
286+ context. Context
286287
287288 mu sync.Mutex
288289 status int
0 commit comments