Blame


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