forked from docker-archive/go-p9p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
48 lines (38 loc) · 996 Bytes
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package p9p
import (
"context"
"time"
)
type contextKey string
const (
versionKey contextKey = "9p.version"
)
func withVersion(ctx context.Context, version string) context.Context {
return context.WithValue(ctx, versionKey, version)
}
// GetVersion returns the protocol version from the context. If the version is
// not known, an empty string is returned. This is typically set on the
// context passed into function calls in a server implementation.
func GetVersion(ctx context.Context) string {
v, ok := ctx.Value(versionKey).(string)
if !ok {
return ""
}
return v
}
// Simple context representing a past-due deadline.
type CancelledCtxt struct{}
func (_ CancelledCtxt) Deadline() (time.Time, bool) {
return time.Time{}, false
}
func (_ CancelledCtxt) Done() <-chan struct{} {
ch := make(chan struct{})
close(ch)
return ch
}
func (_ CancelledCtxt) Err() error {
return context.Canceled
}
func (_ CancelledCtxt) Value(key interface{}) (val interface{}) {
return nil
}