...
1
2
3
4
5
6
7 package operation
8
9 import (
10 "context"
11 "errors"
12
13 "go.mongodb.org/mongo-driver/event"
14 "go.mongodb.org/mongo-driver/internal/driverutil"
15 "go.mongodb.org/mongo-driver/mongo/description"
16 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
17 "go.mongodb.org/mongo-driver/x/mongo/driver"
18 "go.mongodb.org/mongo-driver/x/mongo/driver/session"
19 )
20
21
22 type EndSessions struct {
23 sessionIDs bsoncore.Document
24 session *session.Client
25 clock *session.ClusterClock
26 monitor *event.CommandMonitor
27 crypt driver.Crypt
28 database string
29 deployment driver.Deployment
30 selector description.ServerSelector
31 serverAPI *driver.ServerAPIOptions
32 }
33
34
35 func NewEndSessions(sessionIDs bsoncore.Document) *EndSessions {
36 return &EndSessions{
37 sessionIDs: sessionIDs,
38 }
39 }
40
41 func (es *EndSessions) processResponse(driver.ResponseInfo) error {
42 var err error
43 return err
44 }
45
46
47 func (es *EndSessions) Execute(ctx context.Context) error {
48 if es.deployment == nil {
49 return errors.New("the EndSessions operation must have a Deployment set before Execute can be called")
50 }
51
52 return driver.Operation{
53 CommandFn: es.command,
54 ProcessResponseFn: es.processResponse,
55 Client: es.session,
56 Clock: es.clock,
57 CommandMonitor: es.monitor,
58 Crypt: es.crypt,
59 Database: es.database,
60 Deployment: es.deployment,
61 Selector: es.selector,
62 ServerAPI: es.serverAPI,
63 Name: driverutil.EndSessionsOp,
64 }.Execute(ctx)
65
66 }
67
68 func (es *EndSessions) command(dst []byte, _ description.SelectedServer) ([]byte, error) {
69 if es.sessionIDs != nil {
70 dst = bsoncore.AppendArrayElement(dst, "endSessions", es.sessionIDs)
71 }
72 return dst, nil
73 }
74
75
76 func (es *EndSessions) SessionIDs(sessionIDs bsoncore.Document) *EndSessions {
77 if es == nil {
78 es = new(EndSessions)
79 }
80
81 es.sessionIDs = sessionIDs
82 return es
83 }
84
85
86 func (es *EndSessions) Session(session *session.Client) *EndSessions {
87 if es == nil {
88 es = new(EndSessions)
89 }
90
91 es.session = session
92 return es
93 }
94
95
96 func (es *EndSessions) ClusterClock(clock *session.ClusterClock) *EndSessions {
97 if es == nil {
98 es = new(EndSessions)
99 }
100
101 es.clock = clock
102 return es
103 }
104
105
106 func (es *EndSessions) CommandMonitor(monitor *event.CommandMonitor) *EndSessions {
107 if es == nil {
108 es = new(EndSessions)
109 }
110
111 es.monitor = monitor
112 return es
113 }
114
115
116 func (es *EndSessions) Crypt(crypt driver.Crypt) *EndSessions {
117 if es == nil {
118 es = new(EndSessions)
119 }
120
121 es.crypt = crypt
122 return es
123 }
124
125
126 func (es *EndSessions) Database(database string) *EndSessions {
127 if es == nil {
128 es = new(EndSessions)
129 }
130
131 es.database = database
132 return es
133 }
134
135
136 func (es *EndSessions) Deployment(deployment driver.Deployment) *EndSessions {
137 if es == nil {
138 es = new(EndSessions)
139 }
140
141 es.deployment = deployment
142 return es
143 }
144
145
146 func (es *EndSessions) ServerSelector(selector description.ServerSelector) *EndSessions {
147 if es == nil {
148 es = new(EndSessions)
149 }
150
151 es.selector = selector
152 return es
153 }
154
155
156 func (es *EndSessions) ServerAPI(serverAPI *driver.ServerAPIOptions) *EndSessions {
157 if es == nil {
158 es = new(EndSessions)
159 }
160
161 es.serverAPI = serverAPI
162 return es
163 }
164
View as plain text