Struct: request.HandlerList

import "../ibm-cos-sdk-go/aws/request"

Overview

A HandlerList manages zero or more handlers in a list.

Implemented Interfaces

s3crypto.Cipher, s3manager.ReadSeekerWriteTo, s3manager.WriterReadFrom

Method Summary collapse

Method Details

func (l *HandlerList) Clear()

Clear clears the handler list.



156
157
158
// File 'aws/request/handlers.go', line 156

func (l *HandlerList) Clear() { l.list = l.list[0:0] }

func (l *HandlerList) Len() int

Len returns the number of handlers in the list.



161
162
163
// File 'aws/request/handlers.go', line 161

func (l *HandlerList) Len() int { return len(l.list) }

func (l *HandlerList) PushBack(f func(*Request))

PushBack pushes handler f to the back of the handler list.



166
167
168
// File 'aws/request/handlers.go', line 166

func (l *HandlerList) PushBack(f func(*Request)) { l.PushBackNamed(NamedHandler{"__anonymous", f}) }

func (l *HandlerList) PushBackNamed(n NamedHandler)

PushBackNamed pushes named handler f to the back of the handler list.



171
172
173
174
175
176
// File 'aws/request/handlers.go', line 171

func (l *HandlerList) PushBackNamed(n NamedHandler) { if cap(l.list) == 0 { l.list = make([]NamedHandler, 0, 5) } l.list = append(l.list, n) }

func (l *HandlerList) PushFront(f func(*Request))

PushFront pushes handler f to the front of the handler list.



179
180
181
// File 'aws/request/handlers.go', line 179

func (l *HandlerList) PushFront(f func(*Request)) { l.PushFrontNamed(NamedHandler{"__anonymous", f}) }

func (l *HandlerList) PushFrontNamed(n NamedHandler)

PushFrontNamed pushes named handler f to the front of the handler list.



184
185
186
187
188
189
190
191
192
193
194
// File 'aws/request/handlers.go', line 184

func (l *HandlerList) PushFrontNamed(n NamedHandler) { if cap(l.list) == len(l.list) { // Allocating new list required l.list = append([]NamedHandler{n}, l.list...) } else { // Enough room to prepend into list. l.list = append(l.list, NamedHandler{}) copy(l.list[1:], l.list) l.list[0] = n } }

func (l *HandlerList) Remove(n NamedHandler)

Remove removes a NamedHandler n



197
198
199
// File 'aws/request/handlers.go', line 197

func (l *HandlerList) Remove(n NamedHandler) { l.RemoveByName(n.Name) }

func (l *HandlerList) RemoveByName(name string)

RemoveByName removes a NamedHandler by name.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
// File 'aws/request/handlers.go', line 202

func (l *HandlerList) RemoveByName(name string) { for i := 0; i < len(l.list); i++ { m := l.list[i] if m.Name == name { // Shift array preventing creating new arrays copy(l.list[i:], l.list[i+1:]) l.list[len(l.list)-1] = NamedHandler{} l.list = l.list[:len(l.list)-1] // decrement list so next check to length is correct i-- } } }

func (l *HandlerList) Run(r *Request)

Run executes all handlers in the list with a given request object.



264
265
266
267
268
269
270
271
272
273
274
// File 'aws/request/handlers.go', line 264

func (l *HandlerList) Run(r *Request) { for i, h := range l.list { h.Fn(r) item := HandlerListRunItem{ Index: i, Handler: h, Request: r, } if l.AfterEachFn != nil && !l.AfterEachFn(item) { return } } }

func (l *HandlerList) SetBackNamed(n NamedHandler)

SetBackNamed will replace the named handler if it exists in the handler list. If the handler does not exist the handler will be added to the end of the list.



248
249
250
251
252
// File 'aws/request/handlers.go', line 248

func (l *HandlerList) SetBackNamed(n NamedHandler) { if !l.SwapNamed(n) { l.PushBackNamed(n) } }

func (l *HandlerList) SetFrontNamed(n NamedHandler)

SetFrontNamed will replace the named handler if it exists in the handler list. If the handler does not exist the handler will be added to the beginning of the list.



257
258
259
260
261
// File 'aws/request/handlers.go', line 257

func (l *HandlerList) SetFrontNamed(n NamedHandler) { if !l.SwapNamed(n) { l.PushFrontNamed(n) } }

func (l *HandlerList) Swap(name string, replace NamedHandler) bool

Swap will swap out all handlers matching the name passed in. The matched handlers will be swapped in. True is returned if the handlers were swapped.



233
234
235
236
237
238
239
240
241
242
243
244
// File 'aws/request/handlers.go', line 233

func (l *HandlerList) Swap(name string, replace NamedHandler) bool { var swapped bool for i := 0; i < len(l.list); i++ { if l.list[i].Name == name { l.list[i] = replace swapped = true } } return swapped }

func (l *HandlerList) SwapNamed(n NamedHandler) (swapped bool)

SwapNamed will swap out any existing handlers with the same name as the passed in NamedHandler returning true if handlers were swapped. False is returned otherwise.



220
221
222
223
224
225
226
227
228
229
// File 'aws/request/handlers.go', line 220

func (l *HandlerList) SwapNamed(n NamedHandler) (swapped bool) { for i := 0; i < len(l.list); i++ { if l.list[i].Name == n.Name { l.list[i].Fn = n.Fn swapped = true } } return swapped }