-
Notifications
You must be signed in to change notification settings - Fork 510
/
userd.go
47 lines (36 loc) · 881 Bytes
/
userd.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
35
36
37
38
39
40
41
42
43
44
45
46
47
package daemon
import (
"context"
"google.golang.org/grpc"
"github.com/telepresenceio/telepresence/rpc/v2/connector"
)
type UserClient struct {
connector.ConnectorClient
Conn *grpc.ClientConn
Remote bool
}
type Session struct {
UserClient
Info *connector.ConnectInfo
Started bool
}
type userDaemonKey struct{}
func GetUserClient(ctx context.Context) *UserClient {
if ud, ok := ctx.Value(userDaemonKey{}).(*UserClient); ok {
return ud
}
return nil
}
func WithUserClient(ctx context.Context, ud *UserClient) context.Context {
return context.WithValue(ctx, userDaemonKey{}, ud)
}
type sessionKey struct{}
func GetSession(ctx context.Context) *Session {
if s, ok := ctx.Value(sessionKey{}).(*Session); ok {
return s
}
return nil
}
func WithSession(ctx context.Context, s *Session) context.Context {
return context.WithValue(ctx, sessionKey{}, s)
}