1 dce371f6 2015-11-05 stephen.d package p9pnew
3 dce371f6 2015-11-05 stephen.d import (
4 dce371f6 2015-11-05 stephen.d "golang.org/x/net/context"
7 dce371f6 2015-11-05 stephen.d type contextKey string
10 dce371f6 2015-11-05 stephen.d versionKey contextKey = "9p.version"
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)
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 ""
25 dce371f6 2015-11-05 stephen.d return v