11package lars
22
33import (
4+ "context"
45 "encoding/json"
56 "encoding/xml"
67 "io"
@@ -10,7 +11,6 @@ import (
1011 "time"
1112
1213 "github.com/gorilla/websocket"
13- "golang.org/x/net/context"
1414)
1515
1616// Param is a single URL parameter, consisting of a key and a value.
@@ -61,21 +61,6 @@ type Context interface {
6161 BaseContext () * Ctx
6262}
6363
64- // Ctx encapsulates the http request, response context
65- type Ctx struct {
66- netContext context.Context
67- request * http.Request
68- response * Response
69- websocket * websocket.Conn
70- params Params
71- handlers HandlersChain
72- parent Context
73- handlerName string
74- index int
75- formParsed bool
76- multipartFormParsed bool
77- }
78-
7964var _ context.Context = & Ctx {}
8065
8166// NewContext returns a new default lars Context object.
@@ -117,18 +102,6 @@ func (c *Ctx) WebSocket() *websocket.Conn {
117102func (c * Ctx ) RequestEnd () {
118103}
119104
120- // RequestStart resets the Context to it's default request state
121- func (c * Ctx ) RequestStart (w http.ResponseWriter , r * http.Request ) {
122- c .request = r
123- c .response .reset (w )
124- c .params = c .params [0 :0 ]
125- c .netContext = context .Background () // in go 1.7 will call r.Context(), netContext will go away and be replaced with the Request objects Context
126- c .index = - 1
127- c .handlers = nil
128- c .formParsed = false
129- c .multipartFormParsed = false
130- }
131-
132105// Param returns the value of the first Param which key matches the given name.
133106// If no matching Param is found, an empty string is returned.
134107func (c * Ctx ) Param (name string ) string {
@@ -189,22 +162,6 @@ func (c *Ctx) ParseMultipartForm(maxMemory int64) error {
189162 return nil
190163}
191164
192- // Set is used to store a new key/value pair using the
193- // golang.org/x/net/context contained on this Context.
194- // It is a shortcut for context.WithValue(..., ...)
195- func (c * Ctx ) Set (key interface {}, value interface {}) {
196- c .netContext = context .WithValue (c .netContext , key , value )
197- }
198-
199- // Get returns the value for the given key and is a shortcut
200- // for the golang.org/x/net/context context.Value(...) ... but it
201- // also returns if the value was found or not.
202- func (c * Ctx ) Get (key interface {}) (value interface {}, exists bool ) {
203- value = c .netContext .Value (key )
204- exists = value != nil
205- return
206- }
207-
208165// Next should be used only inside middleware.
209166// It executes the pending handlers in the chain inside the calling handler.
210167// See example in github.
@@ -457,67 +414,3 @@ func (c *Ctx) Decode(includeFormQueryParams bool, maxMemory int64, v interface{}
457414 }
458415 return
459416}
460-
461- // golang.org/x/net/context functions to comply with context.Context interface and keep context update on lars.Context object
462-
463- // Context returns the request's context. To change the context, use
464- // WithContext.
465- //
466- // The returned context is always non-nil.
467- func (c * Ctx ) Context () context.Context {
468- return c .netContext // TODO: in go 1.7 return c.request.Context()
469- }
470-
471- // WithContext updates the underlying request's context with to ctx
472- // The provided ctx must be non-nil.
473- func (c * Ctx ) WithContext (ctx context.Context ) {
474- c .netContext = ctx // TODO: in go 1.7 must update Request object after calling c.request.WithContext(...)
475- }
476-
477- // Deadline calls the underlying golang.org/x/net/context Deadline()
478- func (c * Ctx ) Deadline () (deadline time.Time , ok bool ) {
479- return c .netContext .Deadline ()
480- }
481-
482- // Done calls the underlying golang.org/x/net/context Done()
483- func (c * Ctx ) Done () <- chan struct {} {
484- return c .netContext .Done ()
485- }
486-
487- // Err calls the underlying golang.org/x/net/context Err()
488- func (c * Ctx ) Err () error {
489- return c .netContext .Err ()
490- }
491-
492- // Value calls the underlying golang.org/x/net/context Value()
493- func (c * Ctx ) Value (key interface {}) interface {} {
494- return c .netContext .Value (key )
495- }
496-
497- // WithCancel calls golang.org/x/net/context WithCancel and automatically
498- // updates context on the containing las.Context object.
499- func (c * Ctx ) WithCancel () (cf context.CancelFunc ) {
500- c .netContext , cf = context .WithCancel (c .netContext )
501- return
502- }
503-
504- // WithDeadline calls golang.org/x/net/context WithDeadline and automatically
505- // updates context on the containing las.Context object.
506- func (c * Ctx ) WithDeadline (deadline time.Time ) (cf context.CancelFunc ) {
507- c .netContext , cf = context .WithDeadline (c .netContext , deadline )
508- return
509- }
510-
511- // WithTimeout calls golang.org/x/net/context WithTimeout and automatically
512- // updates context on the containing las.Context object.
513- func (c * Ctx ) WithTimeout (timeout time.Duration ) (cf context.CancelFunc ) {
514- c .netContext , cf = context .WithTimeout (c .netContext , timeout )
515- return
516- }
517-
518- // WithValue calls golang.org/x/net/context WithValue and automatically
519- // updates context on the containing las.Context object.
520- // Can also use Set() function on Context object (Recommended)
521- func (c * Ctx ) WithValue (key interface {}, val interface {}) {
522- c .netContext = context .WithValue (c .netContext , key , val )
523- }
0 commit comments