-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsession.go
72 lines (56 loc) · 1.42 KB
/
session.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package v3io
import (
"sync/atomic"
"github.com/nuclio/logger"
)
// TODO: Request should have a global pool
var requestID uint64 = 0
type Session struct {
Sync *SyncSession
logger logger.Logger
context *Context
}
func newSession(parentLogger logger.Logger,
context *Context,
username string,
password string,
label string,
sessionKey string) (*Session, error) {
newSyncSession, err := newSyncSession(parentLogger, context.Sync, username, password, label, sessionKey)
if err != nil {
return nil, err
}
return &Session{
logger: parentLogger.GetChild("session"),
context: context,
Sync: newSyncSession,
}, nil
}
func (s *Session) NewContainer(alias string) (*Container, error) {
return newContainer(s.logger, s, alias)
}
func (s *Session) ListAll(input *ListAllInput,
context interface{},
responseChan chan *Response) (*Request, error) {
id := atomic.AddUint64(&requestID, 1)
requestResponse := &RequestResponse{
Request: Request{
ID: id,
Input: input,
Context: context,
responseChan: responseChan,
},
}
// point to container
requestResponse.Request.requestResponse = requestResponse
if err := s.sendRequest(&requestResponse.Request); err != nil {
return nil, err
}
return &requestResponse.Request, nil
}
func (s *Session) sendRequest(request *Request) error {
// set session
request.session = s
// delegate to context
return s.context.sendRequest(request)
}