Blame


1 dce371f6 2015-11-05 stephen.d package p9pnew
2 dce371f6 2015-11-05 stephen.d
3 dce371f6 2015-11-05 stephen.d import (
4 dce371f6 2015-11-05 stephen.d "golang.org/x/net/context"
5 dce371f6 2015-11-05 stephen.d )
6 dce371f6 2015-11-05 stephen.d
7 dce371f6 2015-11-05 stephen.d type contextKey string
8 dce371f6 2015-11-05 stephen.d
9 dce371f6 2015-11-05 stephen.d const (
10 dce371f6 2015-11-05 stephen.d versionKey contextKey = "9p.version"
11 dce371f6 2015-11-05 stephen.d )
12 dce371f6 2015-11-05 stephen.d
13 dce371f6 2015-11-05 stephen.d func withVersion(ctx context.Context, version string) context.Context {
14 dce371f6 2015-11-05 stephen.d return context.WithValue(ctx, versionKey, version)
15 dce371f6 2015-11-05 stephen.d }
16 dce371f6 2015-11-05 stephen.d
17 dce371f6 2015-11-05 stephen.d // GetVersion returns the protocol version from the context. If the version is
18 dce371f6 2015-11-05 stephen.d // not known, an empty string is returned. This is typically set on the
19 dce371f6 2015-11-05 stephen.d // context passed into function calls in a server implementation.
20 dce371f6 2015-11-05 stephen.d func GetVersion(ctx context.Context) string {
21 dce371f6 2015-11-05 stephen.d v, ok := ctx.Value(versionKey).(string)
22 dce371f6 2015-11-05 stephen.d if !ok {
23 dce371f6 2015-11-05 stephen.d return ""
24 dce371f6 2015-11-05 stephen.d }
25 dce371f6 2015-11-05 stephen.d return v
26 dce371f6 2015-11-05 stephen.d }