-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
34 lines (26 loc) · 1005 Bytes
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package telnet
import (
"context"
"github.com/soupstoregames/coda-mud/simulation/model"
)
type key int
const (
connectionIDKey key = iota
characterIDKey
)
// WithCharacterID returns the given context with the character ID in it.
func WithCharacterID(parent context.Context, characterID model.CharacterID) context.Context {
return context.WithValue(parent, characterIDKey, characterID)
}
// CharacterIDFromContext extracts the character ID embedded in the context.
func CharacterIDFromContext(c context.Context) model.CharacterID {
return c.Value(characterIDKey).(model.CharacterID)
}
// WithConnectionID returns the given context with the connection ID in it.
func WithConnectionID(parent context.Context, connectionID string) context.Context {
return context.WithValue(parent, characterIDKey, connectionID)
}
// ConnectionIDFromContext extracts the connection ID embedded in the context.
func ConnectionIDFromContext(c context.Context) string {
return c.Value(connectionIDKey).(string)
}