diff options
author | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
---|---|---|
committer | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
commit | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/golang.org/x/net/context | |
parent | 07971ca38143c5faf951d152fba370ddcbe26ad5 (diff) | |
download | terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip |
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/golang.org/x/net/context')
-rw-r--r-- | vendor/golang.org/x/net/context/context.go | 54 | ||||
-rw-r--r-- | vendor/golang.org/x/net/context/go17.go | 72 | ||||
-rw-r--r-- | vendor/golang.org/x/net/context/go19.go | 20 | ||||
-rw-r--r-- | vendor/golang.org/x/net/context/pre_go17.go | 300 | ||||
-rw-r--r-- | vendor/golang.org/x/net/context/pre_go19.go | 109 |
5 files changed, 555 insertions, 0 deletions
diff --git a/vendor/golang.org/x/net/context/context.go b/vendor/golang.org/x/net/context/context.go new file mode 100644 index 0000000..d3681ab --- /dev/null +++ b/vendor/golang.org/x/net/context/context.go | |||
@@ -0,0 +1,54 @@ | |||
1 | // Copyright 2014 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // Package context defines the Context type, which carries deadlines, | ||
6 | // cancelation signals, and other request-scoped values across API boundaries | ||
7 | // and between processes. | ||
8 | // | ||
9 | // Incoming requests to a server should create a Context, and outgoing calls to | ||
10 | // servers should accept a Context. The chain of function calls between must | ||
11 | // propagate the Context, optionally replacing it with a modified copy created | ||
12 | // using WithDeadline, WithTimeout, WithCancel, or WithValue. | ||
13 | // | ||
14 | // Programs that use Contexts should follow these rules to keep interfaces | ||
15 | // consistent across packages and enable static analysis tools to check context | ||
16 | // propagation: | ||
17 | // | ||
18 | // Do not store Contexts inside a struct type; instead, pass a Context | ||
19 | // explicitly to each function that needs it. The Context should be the first | ||
20 | // parameter, typically named ctx: | ||
21 | // | ||
22 | // func DoSomething(ctx context.Context, arg Arg) error { | ||
23 | // // ... use ctx ... | ||
24 | // } | ||
25 | // | ||
26 | // Do not pass a nil Context, even if a function permits it. Pass context.TODO | ||
27 | // if you are unsure about which Context to use. | ||
28 | // | ||
29 | // Use context Values only for request-scoped data that transits processes and | ||
30 | // APIs, not for passing optional parameters to functions. | ||
31 | // | ||
32 | // The same Context may be passed to functions running in different goroutines; | ||
33 | // Contexts are safe for simultaneous use by multiple goroutines. | ||
34 | // | ||
35 | // See http://blog.golang.org/context for example code for a server that uses | ||
36 | // Contexts. | ||
37 | package context // import "golang.org/x/net/context" | ||
38 | |||
39 | // Background returns a non-nil, empty Context. It is never canceled, has no | ||
40 | // values, and has no deadline. It is typically used by the main function, | ||
41 | // initialization, and tests, and as the top-level Context for incoming | ||
42 | // requests. | ||
43 | func Background() Context { | ||
44 | return background | ||
45 | } | ||
46 | |||
47 | // TODO returns a non-nil, empty Context. Code should use context.TODO when | ||
48 | // it's unclear which Context to use or it is not yet available (because the | ||
49 | // surrounding function has not yet been extended to accept a Context | ||
50 | // parameter). TODO is recognized by static analysis tools that determine | ||
51 | // whether Contexts are propagated correctly in a program. | ||
52 | func TODO() Context { | ||
53 | return todo | ||
54 | } | ||
diff --git a/vendor/golang.org/x/net/context/go17.go b/vendor/golang.org/x/net/context/go17.go new file mode 100644 index 0000000..d20f52b --- /dev/null +++ b/vendor/golang.org/x/net/context/go17.go | |||
@@ -0,0 +1,72 @@ | |||
1 | // Copyright 2016 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build go1.7 | ||
6 | |||
7 | package context | ||
8 | |||
9 | import ( | ||
10 | "context" // standard library's context, as of Go 1.7 | ||
11 | "time" | ||
12 | ) | ||
13 | |||
14 | var ( | ||
15 | todo = context.TODO() | ||
16 | background = context.Background() | ||
17 | ) | ||
18 | |||
19 | // Canceled is the error returned by Context.Err when the context is canceled. | ||
20 | var Canceled = context.Canceled | ||
21 | |||
22 | // DeadlineExceeded is the error returned by Context.Err when the context's | ||
23 | // deadline passes. | ||
24 | var DeadlineExceeded = context.DeadlineExceeded | ||
25 | |||
26 | // WithCancel returns a copy of parent with a new Done channel. The returned | ||
27 | // context's Done channel is closed when the returned cancel function is called | ||
28 | // or when the parent context's Done channel is closed, whichever happens first. | ||
29 | // | ||
30 | // Canceling this context releases resources associated with it, so code should | ||
31 | // call cancel as soon as the operations running in this Context complete. | ||
32 | func WithCancel(parent Context) (ctx Context, cancel CancelFunc) { | ||
33 | ctx, f := context.WithCancel(parent) | ||
34 | return ctx, CancelFunc(f) | ||
35 | } | ||
36 | |||
37 | // WithDeadline returns a copy of the parent context with the deadline adjusted | ||
38 | // to be no later than d. If the parent's deadline is already earlier than d, | ||
39 | // WithDeadline(parent, d) is semantically equivalent to parent. The returned | ||
40 | // context's Done channel is closed when the deadline expires, when the returned | ||
41 | // cancel function is called, or when the parent context's Done channel is | ||
42 | // closed, whichever happens first. | ||
43 | // | ||
44 | // Canceling this context releases resources associated with it, so code should | ||
45 | // call cancel as soon as the operations running in this Context complete. | ||
46 | func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) { | ||
47 | ctx, f := context.WithDeadline(parent, deadline) | ||
48 | return ctx, CancelFunc(f) | ||
49 | } | ||
50 | |||
51 | // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)). | ||
52 | // | ||
53 | // Canceling this context releases resources associated with it, so code should | ||
54 | // call cancel as soon as the operations running in this Context complete: | ||
55 | // | ||
56 | // func slowOperationWithTimeout(ctx context.Context) (Result, error) { | ||
57 | // ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond) | ||
58 | // defer cancel() // releases resources if slowOperation completes before timeout elapses | ||
59 | // return slowOperation(ctx) | ||
60 | // } | ||
61 | func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) { | ||
62 | return WithDeadline(parent, time.Now().Add(timeout)) | ||
63 | } | ||
64 | |||
65 | // WithValue returns a copy of parent in which the value associated with key is | ||
66 | // val. | ||
67 | // | ||
68 | // Use context Values only for request-scoped data that transits processes and | ||
69 | // APIs, not for passing optional parameters to functions. | ||
70 | func WithValue(parent Context, key interface{}, val interface{}) Context { | ||
71 | return context.WithValue(parent, key, val) | ||
72 | } | ||
diff --git a/vendor/golang.org/x/net/context/go19.go b/vendor/golang.org/x/net/context/go19.go new file mode 100644 index 0000000..d88bd1d --- /dev/null +++ b/vendor/golang.org/x/net/context/go19.go | |||
@@ -0,0 +1,20 @@ | |||
1 | // Copyright 2017 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build go1.9 | ||
6 | |||
7 | package context | ||
8 | |||
9 | import "context" // standard library's context, as of Go 1.7 | ||
10 | |||
11 | // A Context carries a deadline, a cancelation signal, and other values across | ||
12 | // API boundaries. | ||
13 | // | ||
14 | // Context's methods may be called by multiple goroutines simultaneously. | ||
15 | type Context = context.Context | ||
16 | |||
17 | // A CancelFunc tells an operation to abandon its work. | ||
18 | // A CancelFunc does not wait for the work to stop. | ||
19 | // After the first call, subsequent calls to a CancelFunc do nothing. | ||
20 | type CancelFunc = context.CancelFunc | ||
diff --git a/vendor/golang.org/x/net/context/pre_go17.go b/vendor/golang.org/x/net/context/pre_go17.go new file mode 100644 index 0000000..0f35592 --- /dev/null +++ b/vendor/golang.org/x/net/context/pre_go17.go | |||
@@ -0,0 +1,300 @@ | |||
1 | // Copyright 2014 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build !go1.7 | ||
6 | |||
7 | package context | ||
8 | |||
9 | import ( | ||
10 | "errors" | ||
11 | "fmt" | ||
12 | "sync" | ||
13 | "time" | ||
14 | ) | ||
15 | |||
16 | // An emptyCtx is never canceled, has no values, and has no deadline. It is not | ||
17 | // struct{}, since vars of this type must have distinct addresses. | ||
18 | type emptyCtx int | ||
19 | |||
20 | func (*emptyCtx) Deadline() (deadline time.Time, ok bool) { | ||
21 | return | ||
22 | } | ||
23 | |||
24 | func (*emptyCtx) Done() <-chan struct{} { | ||
25 | return nil | ||
26 | } | ||
27 | |||
28 | func (*emptyCtx) Err() error { | ||
29 | return nil | ||
30 | } | ||
31 | |||
32 | func (*emptyCtx) Value(key interface{}) interface{} { | ||
33 | return nil | ||
34 | } | ||
35 | |||
36 | func (e *emptyCtx) String() string { | ||
37 | switch e { | ||
38 | case background: | ||
39 | return "context.Background" | ||
40 | case todo: | ||
41 | return "context.TODO" | ||
42 | } | ||
43 | return "unknown empty Context" | ||
44 | } | ||
45 | |||
46 | var ( | ||
47 | background = new(emptyCtx) | ||
48 | todo = new(emptyCtx) | ||
49 | ) | ||
50 | |||
51 | // Canceled is the error returned by Context.Err when the context is canceled. | ||
52 | var Canceled = errors.New("context canceled") | ||
53 | |||
54 | // DeadlineExceeded is the error returned by Context.Err when the context's | ||
55 | // deadline passes. | ||
56 | var DeadlineExceeded = errors.New("context deadline exceeded") | ||
57 | |||
58 | // WithCancel returns a copy of parent with a new Done channel. The returned | ||
59 | // context's Done channel is closed when the returned cancel function is called | ||
60 | // or when the parent context's Done channel is closed, whichever happens first. | ||
61 | // | ||
62 | // Canceling this context releases resources associated with it, so code should | ||
63 | // call cancel as soon as the operations running in this Context complete. | ||
64 | func WithCancel(parent Context) (ctx Context, cancel CancelFunc) { | ||
65 | c := newCancelCtx(parent) | ||
66 | propagateCancel(parent, c) | ||
67 | return c, func() { c.cancel(true, Canceled) } | ||
68 | } | ||
69 | |||
70 | // newCancelCtx returns an initialized cancelCtx. | ||
71 | func newCancelCtx(parent Context) *cancelCtx { | ||
72 | return &cancelCtx{ | ||
73 | Context: parent, | ||
74 | done: make(chan struct{}), | ||
75 | } | ||
76 | } | ||
77 | |||
78 | // propagateCancel arranges for child to be canceled when parent is. | ||
79 | func propagateCancel(parent Context, child canceler) { | ||
80 | if parent.Done() == nil { | ||
81 | return // parent is never canceled | ||
82 | } | ||
83 | if p, ok := parentCancelCtx(parent); ok { | ||
84 | p.mu.Lock() | ||
85 | if p.err != nil { | ||
86 | // parent has already been canceled | ||
87 | child.cancel(false, p.err) | ||
88 | } else { | ||
89 | if p.children == nil { | ||
90 | p.children = make(map[canceler]bool) | ||
91 | } | ||
92 | p.children[child] = true | ||
93 | } | ||
94 | p.mu.Unlock() | ||
95 | } else { | ||
96 | go func() { | ||
97 | select { | ||
98 | case <-parent.Done(): | ||
99 | child.cancel(false, parent.Err()) | ||
100 | case <-child.Done(): | ||
101 | } | ||
102 | }() | ||
103 | } | ||
104 | } | ||
105 | |||
106 | // parentCancelCtx follows a chain of parent references until it finds a | ||
107 | // *cancelCtx. This function understands how each of the concrete types in this | ||
108 | // package represents its parent. | ||
109 | func parentCancelCtx(parent Context) (*cancelCtx, bool) { | ||
110 | for { | ||
111 | switch c := parent.(type) { | ||
112 | case *cancelCtx: | ||
113 | return c, true | ||
114 | case *timerCtx: | ||
115 | return c.cancelCtx, true | ||
116 | case *valueCtx: | ||
117 | parent = c.Context | ||
118 | default: | ||
119 | return nil, false | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 | // removeChild removes a context from its parent. | ||
125 | func removeChild(parent Context, child canceler) { | ||
126 | p, ok := parentCancelCtx(parent) | ||
127 | if !ok { | ||
128 | return | ||
129 | } | ||
130 | p.mu.Lock() | ||
131 | if p.children != nil { | ||
132 | delete(p.children, child) | ||
133 | } | ||
134 | p.mu.Unlock() | ||
135 | } | ||
136 | |||
137 | // A canceler is a context type that can be canceled directly. The | ||
138 | // implementations are *cancelCtx and *timerCtx. | ||
139 | type canceler interface { | ||
140 | cancel(removeFromParent bool, err error) | ||
141 | Done() <-chan struct{} | ||
142 | } | ||
143 | |||
144 | // A cancelCtx can be canceled. When canceled, it also cancels any children | ||
145 | // that implement canceler. | ||
146 | type cancelCtx struct { | ||
147 | Context | ||
148 | |||
149 | done chan struct{} // closed by the first cancel call. | ||
150 | |||
151 | mu sync.Mutex | ||
152 | children map[canceler]bool // set to nil by the first cancel call | ||
153 | err error // set to non-nil by the first cancel call | ||
154 | } | ||
155 | |||
156 | func (c *cancelCtx) Done() <-chan struct{} { | ||
157 | return c.done | ||
158 | } | ||
159 | |||
160 | func (c *cancelCtx) Err() error { | ||
161 | c.mu.Lock() | ||
162 | defer c.mu.Unlock() | ||
163 | return c.err | ||
164 | } | ||
165 | |||
166 | func (c *cancelCtx) String() string { | ||
167 | return fmt.Sprintf("%v.WithCancel", c.Context) | ||
168 | } | ||
169 | |||
170 | // cancel closes c.done, cancels each of c's children, and, if | ||
171 | // removeFromParent is true, removes c from its parent's children. | ||
172 | func (c *cancelCtx) cancel(removeFromParent bool, err error) { | ||
173 | if err == nil { | ||
174 | panic("context: internal error: missing cancel error") | ||
175 | } | ||
176 | c.mu.Lock() | ||
177 | if c.err != nil { | ||
178 | c.mu.Unlock() | ||
179 | return // already canceled | ||
180 | } | ||
181 | c.err = err | ||
182 | close(c.done) | ||
183 | for child := range c.children { | ||
184 | // NOTE: acquiring the child's lock while holding parent's lock. | ||
185 | child.cancel(false, err) | ||
186 | } | ||
187 | c.children = nil | ||
188 | c.mu.Unlock() | ||
189 | |||
190 | if removeFromParent { | ||
191 | removeChild(c.Context, c) | ||
192 | } | ||
193 | } | ||
194 | |||
195 | // WithDeadline returns a copy of the parent context with the deadline adjusted | ||
196 | // to be no later than d. If the parent's deadline is already earlier than d, | ||
197 | // WithDeadline(parent, d) is semantically equivalent to parent. The returned | ||
198 | // context's Done channel is closed when the deadline expires, when the returned | ||
199 | // cancel function is called, or when the parent context's Done channel is | ||
200 | // closed, whichever happens first. | ||
201 | // | ||
202 | // Canceling this context releases resources associated with it, so code should | ||
203 | // call cancel as soon as the operations running in this Context complete. | ||
204 | func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) { | ||
205 | if cur, ok := parent.Deadline(); ok && cur.Before(deadline) { | ||
206 | // The current deadline is already sooner than the new one. | ||
207 | return WithCancel(parent) | ||
208 | } | ||
209 | c := &timerCtx{ | ||
210 | cancelCtx: newCancelCtx(parent), | ||
211 | deadline: deadline, | ||
212 | } | ||
213 | propagateCancel(parent, c) | ||
214 | d := deadline.Sub(time.Now()) | ||
215 | if d <= 0 { | ||
216 | c.cancel(true, DeadlineExceeded) // deadline has already passed | ||
217 | return c, func() { c.cancel(true, Canceled) } | ||
218 | } | ||
219 | c.mu.Lock() | ||
220 | defer c.mu.Unlock() | ||
221 | if c.err == nil { | ||
222 | c.timer = time.AfterFunc(d, func() { | ||
223 | c.cancel(true, DeadlineExceeded) | ||
224 | }) | ||
225 | } | ||
226 | return c, func() { c.cancel(true, Canceled) } | ||
227 | } | ||
228 | |||
229 | // A timerCtx carries a timer and a deadline. It embeds a cancelCtx to | ||
230 | // implement Done and Err. It implements cancel by stopping its timer then | ||
231 | // delegating to cancelCtx.cancel. | ||
232 | type timerCtx struct { | ||
233 | *cancelCtx | ||
234 | timer *time.Timer // Under cancelCtx.mu. | ||
235 | |||
236 | deadline time.Time | ||
237 | } | ||
238 | |||
239 | func (c *timerCtx) Deadline() (deadline time.Time, ok bool) { | ||
240 | return c.deadline, true | ||
241 | } | ||
242 | |||
243 | func (c *timerCtx) String() string { | ||
244 | return fmt.Sprintf("%v.WithDeadline(%s [%s])", c.cancelCtx.Context, c.deadline, c.deadline.Sub(time.Now())) | ||
245 | } | ||
246 | |||
247 | func (c *timerCtx) cancel(removeFromParent bool, err error) { | ||
248 | c.cancelCtx.cancel(false, err) | ||
249 | if removeFromParent { | ||
250 | // Remove this timerCtx from its parent cancelCtx's children. | ||
251 | removeChild(c.cancelCtx.Context, c) | ||
252 | } | ||
253 | c.mu.Lock() | ||
254 | if c.timer != nil { | ||
255 | c.timer.Stop() | ||
256 | c.timer = nil | ||
257 | } | ||
258 | c.mu.Unlock() | ||
259 | } | ||
260 | |||
261 | // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)). | ||
262 | // | ||
263 | // Canceling this context releases resources associated with it, so code should | ||
264 | // call cancel as soon as the operations running in this Context complete: | ||
265 | // | ||
266 | // func slowOperationWithTimeout(ctx context.Context) (Result, error) { | ||
267 | // ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond) | ||
268 | // defer cancel() // releases resources if slowOperation completes before timeout elapses | ||
269 | // return slowOperation(ctx) | ||
270 | // } | ||
271 | func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) { | ||
272 | return WithDeadline(parent, time.Now().Add(timeout)) | ||
273 | } | ||
274 | |||
275 | // WithValue returns a copy of parent in which the value associated with key is | ||
276 | // val. | ||
277 | // | ||
278 | // Use context Values only for request-scoped data that transits processes and | ||
279 | // APIs, not for passing optional parameters to functions. | ||
280 | func WithValue(parent Context, key interface{}, val interface{}) Context { | ||
281 | return &valueCtx{parent, key, val} | ||
282 | } | ||
283 | |||
284 | // A valueCtx carries a key-value pair. It implements Value for that key and | ||
285 | // delegates all other calls to the embedded Context. | ||
286 | type valueCtx struct { | ||
287 | Context | ||
288 | key, val interface{} | ||
289 | } | ||
290 | |||
291 | func (c *valueCtx) String() string { | ||
292 | return fmt.Sprintf("%v.WithValue(%#v, %#v)", c.Context, c.key, c.val) | ||
293 | } | ||
294 | |||
295 | func (c *valueCtx) Value(key interface{}) interface{} { | ||
296 | if c.key == key { | ||
297 | return c.val | ||
298 | } | ||
299 | return c.Context.Value(key) | ||
300 | } | ||
diff --git a/vendor/golang.org/x/net/context/pre_go19.go b/vendor/golang.org/x/net/context/pre_go19.go new file mode 100644 index 0000000..b105f80 --- /dev/null +++ b/vendor/golang.org/x/net/context/pre_go19.go | |||
@@ -0,0 +1,109 @@ | |||
1 | // Copyright 2014 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build !go1.9 | ||
6 | |||
7 | package context | ||
8 | |||
9 | import "time" | ||
10 | |||
11 | // A Context carries a deadline, a cancelation signal, and other values across | ||
12 | // API boundaries. | ||
13 | // | ||
14 | // Context's methods may be called by multiple goroutines simultaneously. | ||
15 | type Context interface { | ||
16 | // Deadline returns the time when work done on behalf of this context | ||
17 | // should be canceled. Deadline returns ok==false when no deadline is | ||
18 | // set. Successive calls to Deadline return the same results. | ||
19 | Deadline() (deadline time.Time, ok bool) | ||
20 | |||
21 | // Done returns a channel that's closed when work done on behalf of this | ||
22 | // context should be canceled. Done may return nil if this context can | ||
23 | // never be canceled. Successive calls to Done return the same value. | ||
24 | // | ||
25 | // WithCancel arranges for Done to be closed when cancel is called; | ||
26 | // WithDeadline arranges for Done to be closed when the deadline | ||
27 | // expires; WithTimeout arranges for Done to be closed when the timeout | ||
28 | // elapses. | ||
29 | // | ||
30 | // Done is provided for use in select statements: | ||
31 | // | ||
32 | // // Stream generates values with DoSomething and sends them to out | ||
33 | // // until DoSomething returns an error or ctx.Done is closed. | ||
34 | // func Stream(ctx context.Context, out chan<- Value) error { | ||
35 | // for { | ||
36 | // v, err := DoSomething(ctx) | ||
37 | // if err != nil { | ||
38 | // return err | ||
39 | // } | ||
40 | // select { | ||
41 | // case <-ctx.Done(): | ||
42 | // return ctx.Err() | ||
43 | // case out <- v: | ||
44 | // } | ||
45 | // } | ||
46 | // } | ||
47 | // | ||
48 | // See http://blog.golang.org/pipelines for more examples of how to use | ||
49 | // a Done channel for cancelation. | ||
50 | Done() <-chan struct{} | ||
51 | |||
52 | // Err returns a non-nil error value after Done is closed. Err returns | ||
53 | // Canceled if the context was canceled or DeadlineExceeded if the | ||
54 | // context's deadline passed. No other values for Err are defined. | ||
55 | // After Done is closed, successive calls to Err return the same value. | ||
56 | Err() error | ||
57 | |||
58 | // Value returns the value associated with this context for key, or nil | ||
59 | // if no value is associated with key. Successive calls to Value with | ||
60 | // the same key returns the same result. | ||
61 | // | ||
62 | // Use context values only for request-scoped data that transits | ||
63 | // processes and API boundaries, not for passing optional parameters to | ||
64 | // functions. | ||
65 | // | ||
66 | // A key identifies a specific value in a Context. Functions that wish | ||
67 | // to store values in Context typically allocate a key in a global | ||
68 | // variable then use that key as the argument to context.WithValue and | ||
69 | // Context.Value. A key can be any type that supports equality; | ||
70 | // packages should define keys as an unexported type to avoid | ||
71 | // collisions. | ||
72 | // | ||
73 | // Packages that define a Context key should provide type-safe accessors | ||
74 | // for the values stores using that key: | ||
75 | // | ||
76 | // // Package user defines a User type that's stored in Contexts. | ||
77 | // package user | ||
78 | // | ||
79 | // import "golang.org/x/net/context" | ||
80 | // | ||
81 | // // User is the type of value stored in the Contexts. | ||
82 | // type User struct {...} | ||
83 | // | ||
84 | // // key is an unexported type for keys defined in this package. | ||
85 | // // This prevents collisions with keys defined in other packages. | ||
86 | // type key int | ||
87 | // | ||
88 | // // userKey is the key for user.User values in Contexts. It is | ||
89 | // // unexported; clients use user.NewContext and user.FromContext | ||
90 | // // instead of using this key directly. | ||
91 | // var userKey key = 0 | ||
92 | // | ||
93 | // // NewContext returns a new Context that carries value u. | ||
94 | // func NewContext(ctx context.Context, u *User) context.Context { | ||
95 | // return context.WithValue(ctx, userKey, u) | ||
96 | // } | ||
97 | // | ||
98 | // // FromContext returns the User value stored in ctx, if any. | ||
99 | // func FromContext(ctx context.Context) (*User, bool) { | ||
100 | // u, ok := ctx.Value(userKey).(*User) | ||
101 | // return u, ok | ||
102 | // } | ||
103 | Value(key interface{}) interface{} | ||
104 | } | ||
105 | |||
106 | // A CancelFunc tells an operation to abandon its work. | ||
107 | // A CancelFunc does not wait for the work to stop. | ||
108 | // After the first call, subsequent calls to a CancelFunc do nothing. | ||
109 | type CancelFunc func() | ||