| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package cache |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import ( |
| 10 |
"golang.org/x/tools/internal/event/label" |
| 11 |
) |
| 12 |
|
| 13 |
var ( |
| 14 |
KeyCreateSession = NewSessionKey("create_session", "A new session was added") |
| 15 |
KeyUpdateSession = NewSessionKey("update_session", "Updated information about a session") |
| 16 |
KeyShutdownSession = NewSessionKey("shutdown_session", "A session was shut down") |
| 17 |
) |
| 18 |
|
| 19 |
|
| 20 |
type SessionKey struct { |
| 21 |
name string |
| 22 |
description string |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
func NewSessionKey(name, description string) *SessionKey { |
| 27 |
return &SessionKey{name: name, description: description} |
| 28 |
} |
| 29 |
|
| 30 |
func (k *SessionKey) Name() string { return k.name } |
| 31 |
func (k *SessionKey) Description() string { return k.description } |
| 32 |
|
| 33 |
func (k *SessionKey) Append(buf []byte, l label.Label) []byte { |
| 34 |
return append(buf, k.From(l).ID()...) |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
func (k *SessionKey) Of(v *Session) label.Label { return label.OfValue(k, v) } |
| 39 |
|
| 40 |
|
| 41 |
func (k *SessionKey) Get(lm label.Map) *Session { |
| 42 |
if t := lm.Find(k); t.Valid() { |
| 43 |
return k.From(t) |
| 44 |
} |
| 45 |
return nil |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
func (k *SessionKey) From(t label.Label) *Session { |
| 50 |
err, _ := t.UnpackValue().(*Session) |
| 51 |
return err |
| 52 |
} |