1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "golang.org/x/tools/internal/event/label"
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")
19 // SessionKey represents an event label key that has a *Session value.
20 type SessionKey struct {
25 // NewSessionKey creates a new Key for *Session values.
26 func NewSessionKey(name, description string) *SessionKey {
27 return &SessionKey{name: name, description: description}
30 func (k *SessionKey) Name() string { return k.name }
31 func (k *SessionKey) Description() string { return k.description }
33 func (k *SessionKey) Format(w io.Writer, buf []byte, l label.Label) {
34 io.WriteString(w, k.From(l).ID())
37 // Of creates a new Label with this key and the supplied session.
38 func (k *SessionKey) Of(v *Session) label.Label { return label.OfValue(k, v) }
40 // Get can be used to get the session for the key from a label.Map.
41 func (k *SessionKey) Get(lm label.Map) *Session {
42 if t := lm.Find(k); t.Valid() {
48 // From can be used to get the session value from a Label.
49 func (k *SessionKey) From(t label.Label) *Session {
50 err, _ := t.UnpackValue().(*Session)