Blob


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