/
op_ListTables.go
225 lines (175 loc) · 6.46 KB
/
op_ListTables.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package dyno
import (
"context"
ddb "github.com/aws/aws-sdk-go-v2/service/dynamodb"
"sync"
)
// ListTables executes ListTables operation and returns a ListTables operation
func (s *Session) ListTables(input *ddb.ListTablesInput, mw ...ListTablesMiddleWare) *ListTables {
return NewListTables(input, mw...).Invoke(s.ctx, s.ddb)
}
// ListTables executes a ListTables operation with a ListTablesInput in this pool and returns the ListTables operation
func (p *Pool) ListTables(input *ddb.ListTablesInput, mw ...ListTablesMiddleWare) *ListTables {
op := NewListTables(input, mw...)
p.Do(op) // run the operation in the pool
return op
}
// ListAllTables executes ListTables operation and returns a ListTables operation
func (s *Session) ListAllTables(input *ddb.ListTablesInput, mw ...ListTablesMiddleWare) *ListTables {
return NewListAllTables(input, mw...).Invoke(s.ctx, s.ddb)
}
// ListAllTables executes a ListTables operation with a ListTablesInput in this pool and returns the ListTables operation
func (p *Pool) ListAllTables(input *ddb.ListTablesInput, mw ...ListTablesMiddleWare) *ListTables {
op := NewListAllTables(input, mw...)
p.Do(op) // run the operation in the pool
return op
}
// ListTablesContext represents an exhaustive ListTables operation request context
type ListTablesContext struct {
context.Context
Input *ddb.ListTablesInput
Client *ddb.Client
}
// ListTablesOutput represents the output for the ListTables operation
type ListTablesOutput struct {
out *ddb.ListTablesOutput
err error
mu sync.RWMutex
}
// Set sets the output
func (o *ListTablesOutput) Set(out *ddb.ListTablesOutput, err error) {
o.mu.Lock()
o.out = out
o.err = err
o.mu.Unlock()
}
// Get gets the output
func (o *ListTablesOutput) Get() (out *ddb.ListTablesOutput, err error) {
o.mu.Lock()
out = o.out
err = o.err
o.mu.Unlock()
return
}
// ListTablesHandler represents a handler for ListTables requests
type ListTablesHandler interface {
HandleListTables(ctx *ListTablesContext, output *ListTablesOutput)
}
// ListTablesHandlerFunc is a ListTablesHandler function
type ListTablesHandlerFunc func(ctx *ListTablesContext, output *ListTablesOutput)
// HandleListTables implements ListTablesHandler
func (h ListTablesHandlerFunc) HandleListTables(ctx *ListTablesContext, output *ListTablesOutput) {
h(ctx, output)
}
// ListTablesFinalHandler is the final ListTablesHandler that executes a dynamodb ListTables operation
type ListTablesFinalHandler struct{}
// HandleListTables implements the ListTablesHandler
func (h *ListTablesFinalHandler) HandleListTables(ctx *ListTablesContext, output *ListTablesOutput) {
output.Set(ctx.Client.ListTables(ctx, ctx.Input))
}
// ListAllTablesFinalHandler is the final ListTablesHandler that executes a dynamodb ListTables operation
type ListAllTablesFinalHandler struct{}
// HandleListTables implements the ListTablesHandler
func (h *ListAllTablesFinalHandler) HandleListTables(ctx *ListTablesContext, output *ListTablesOutput) {
var (
err error
out, finalOutput *ddb.ListTablesOutput
)
input := CopyListTablesInput(ctx.Input)
finalOutput = new(ddb.ListTablesOutput)
defer func() { output.Set(finalOutput, err) }()
for {
out, err = ctx.Client.ListTables(ctx, input)
if err != nil {
output.Set(nil, err)
}
finalOutput.TableNames = append(finalOutput.TableNames, out.TableNames...)
if out.LastEvaluatedTableName == nil || len(*out.LastEvaluatedTableName) == 0 {
return
}
*input.ExclusiveStartTableName = *out.LastEvaluatedTableName
}
}
// ListTablesMiddleWare is a middleware function use for wrapping ListTablesHandler requests
type ListTablesMiddleWare interface {
ListTablesMiddleWare(next ListTablesHandler) ListTablesHandler
}
// ListTablesMiddleWareFunc is a functional ListTablesMiddleWare
type ListTablesMiddleWareFunc func(next ListTablesHandler) ListTablesHandler
// ListTablesMiddleWare implements the ListTablesMiddleWare interface
func (mw ListTablesMiddleWareFunc) ListTablesMiddleWare(next ListTablesHandler) ListTablesHandler {
return mw(next)
}
// ListTables represents a ListTables operation
type ListTables struct {
*BaseOperation
Handler ListTablesHandler
input *ddb.ListTablesInput
middleWares []ListTablesMiddleWare
}
// NewListTables creates a new ListTables operation
func NewListTables(input *ddb.ListTablesInput, mws ...ListTablesMiddleWare) *ListTables {
return &ListTables{
BaseOperation: NewOperation(),
Handler: new(ListTablesFinalHandler),
input: input,
middleWares: mws,
}
}
// NewListAllTables creates a new ListTables operation that lists ALL tables and combines their outputs
func NewListAllTables(input *ddb.ListTablesInput, mws ...ListTablesMiddleWare) *ListTables {
return &ListTables{
BaseOperation: NewOperation(),
Handler: new(ListAllTablesFinalHandler),
input: input,
middleWares: mws,
}
}
// Invoke invokes the ListTables operation in a goroutine and returns a ListTables operation
func (op *ListTables) Invoke(ctx context.Context, client *ddb.Client) *ListTables {
op.SetRunning() // operation now waiting for a response
go op.InvokeDynoOperation(ctx, client)
return op
}
// InvokeDynoOperation invokes the ListTables operation
func (op *ListTables) InvokeDynoOperation(ctx context.Context, client *ddb.Client) {
output := new(ListTablesOutput)
defer func() { op.SetResponse(output.Get()) }()
var h ListTablesHandler
h = op.Handler
// loop in reverse to preserve middleware order
for i := len(op.middleWares) - 1; i >= 0; i-- {
h = op.middleWares[i].ListTablesMiddleWare(h)
}
requestCtx := &ListTablesContext{
Context: ctx,
Client: client,
Input: op.input,
}
h.HandleListTables(requestCtx, output)
}
// Await waits for the ListTables operation to be fulfilled and then returns a ListTablesOutput and error
func (op *ListTables) Await() (*ddb.ListTablesOutput, error) {
out, err := op.BaseOperation.Await()
if out == nil {
return nil, err
}
return out.(*ddb.ListTablesOutput), err
}
// NewListTablesInput creates a new ListTablesInput
func NewListTablesInput() *ddb.ListTablesInput {
return &ddb.ListTablesInput{}
}
// CopyListTablesInput creates a copy of a ListGlobalTablesInput
func CopyListTablesInput(input *ddb.ListTablesInput) *ddb.ListTablesInput {
out := &ddb.ListTablesInput{}
if input.Limit != nil {
out.Limit = new(int32)
*out.Limit = *input.Limit
}
if input.ExclusiveStartTableName != nil {
out.ExclusiveStartTableName = new(string)
*out.ExclusiveStartTableName = *input.ExclusiveStartTableName
}
return out
}