| 1 | package sessionid |
| 2 | |
| 3 | import ( |
| 4 | "golang.org/x/net/context" |
| 5 | ) |
| 6 | |
| 7 | type key int |
| 8 | |
| 9 | const sessionIDKey = 0 |
| 10 | |
| 11 | func NewContext(ctx context.Context, sessionID string) context.Context { |
| 12 | return context.WithValue(ctx, sessionIDKey, sessionID) |
| 13 | } |
| 14 | |
| 15 | func FromContext(ctx context.Context) (string, bool) { |
| 16 | sessionID, ok := ctx.Value(sessionIDKey).(string) |
| 17 | return sessionID, ok |
| 18 | } |