aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/mitchellh/reflectwalk
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mitchellh/reflectwalk')
-rw-r--r--vendor/github.com/mitchellh/reflectwalk/location.go2
-rw-r--r--vendor/github.com/mitchellh/reflectwalk/location_string.go8
-rw-r--r--vendor/github.com/mitchellh/reflectwalk/reflectwalk.go108
3 files changed, 91 insertions, 27 deletions
diff --git a/vendor/github.com/mitchellh/reflectwalk/location.go b/vendor/github.com/mitchellh/reflectwalk/location.go
index 7c59d76..6a7f176 100644
--- a/vendor/github.com/mitchellh/reflectwalk/location.go
+++ b/vendor/github.com/mitchellh/reflectwalk/location.go
@@ -11,6 +11,8 @@ const (
11 MapValue 11 MapValue
12 Slice 12 Slice
13 SliceElem 13 SliceElem
14 Array
15 ArrayElem
14 Struct 16 Struct
15 StructField 17 StructField
16 WalkLoc 18 WalkLoc
diff --git a/vendor/github.com/mitchellh/reflectwalk/location_string.go b/vendor/github.com/mitchellh/reflectwalk/location_string.go
index d3cfe85..70760cf 100644
--- a/vendor/github.com/mitchellh/reflectwalk/location_string.go
+++ b/vendor/github.com/mitchellh/reflectwalk/location_string.go
@@ -1,15 +1,15 @@
1// generated by stringer -type=Location location.go; DO NOT EDIT 1// Code generated by "stringer -type=Location location.go"; DO NOT EDIT.
2 2
3package reflectwalk 3package reflectwalk
4 4
5import "fmt" 5import "fmt"
6 6
7const _Location_name = "NoneMapMapKeyMapValueSliceSliceElemStructStructFieldWalkLoc" 7const _Location_name = "NoneMapMapKeyMapValueSliceSliceElemArrayArrayElemStructStructFieldWalkLoc"
8 8
9var _Location_index = [...]uint8{0, 4, 7, 13, 21, 26, 35, 41, 52, 59} 9var _Location_index = [...]uint8{0, 4, 7, 13, 21, 26, 35, 40, 49, 55, 66, 73}
10 10
11func (i Location) String() string { 11func (i Location) String() string {
12 if i+1 >= Location(len(_Location_index)) { 12 if i >= Location(len(_Location_index)-1) {
13 return fmt.Sprintf("Location(%d)", i) 13 return fmt.Sprintf("Location(%d)", i)
14 } 14 }
15 return _Location_name[_Location_index[i]:_Location_index[i+1]] 15 return _Location_name[_Location_index[i]:_Location_index[i+1]]
diff --git a/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go b/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go
index ec0a623..d7ab7b6 100644
--- a/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go
+++ b/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go
@@ -39,6 +39,13 @@ type SliceWalker interface {
39 SliceElem(int, reflect.Value) error 39 SliceElem(int, reflect.Value) error
40} 40}
41 41
42// ArrayWalker implementations are able to handle array elements found
43// within complex structures.
44type ArrayWalker interface {
45 Array(reflect.Value) error
46 ArrayElem(int, reflect.Value) error
47}
48
42// StructWalker is an interface that has methods that are called for 49// StructWalker is an interface that has methods that are called for
43// structs when a Walk is done. 50// structs when a Walk is done.
44type StructWalker interface { 51type StructWalker interface {
@@ -65,6 +72,7 @@ type PointerWalker interface {
65// SkipEntry can be returned from walk functions to skip walking 72// SkipEntry can be returned from walk functions to skip walking
66// the value of this field. This is only valid in the following functions: 73// the value of this field. This is only valid in the following functions:
67// 74//
75// - Struct: skips all fields from being walked
68// - StructField: skips walking the struct value 76// - StructField: skips walking the struct value
69// 77//
70var SkipEntry = errors.New("skip this entry") 78var SkipEntry = errors.New("skip this entry")
@@ -179,6 +187,9 @@ func walk(v reflect.Value, w interface{}) (err error) {
179 case reflect.Struct: 187 case reflect.Struct:
180 err = walkStruct(v, w) 188 err = walkStruct(v, w)
181 return 189 return
190 case reflect.Array:
191 err = walkArray(v, w)
192 return
182 default: 193 default:
183 panic("unsupported type: " + k.String()) 194 panic("unsupported type: " + k.String())
184 } 195 }
@@ -286,48 +297,99 @@ func walkSlice(v reflect.Value, w interface{}) (err error) {
286 return nil 297 return nil
287} 298}
288 299
300func walkArray(v reflect.Value, w interface{}) (err error) {
301 ew, ok := w.(EnterExitWalker)
302 if ok {
303 ew.Enter(Array)
304 }
305
306 if aw, ok := w.(ArrayWalker); ok {
307 if err := aw.Array(v); err != nil {
308 return err
309 }
310 }
311
312 for i := 0; i < v.Len(); i++ {
313 elem := v.Index(i)
314
315 if aw, ok := w.(ArrayWalker); ok {
316 if err := aw.ArrayElem(i, elem); err != nil {
317 return err
318 }
319 }
320
321 ew, ok := w.(EnterExitWalker)
322 if ok {
323 ew.Enter(ArrayElem)
324 }
325
326 if err := walk(elem, w); err != nil {
327 return err
328 }
329
330 if ok {
331 ew.Exit(ArrayElem)
332 }
333 }
334
335 ew, ok = w.(EnterExitWalker)
336 if ok {
337 ew.Exit(Array)
338 }
339
340 return nil
341}
342
289func walkStruct(v reflect.Value, w interface{}) (err error) { 343func walkStruct(v reflect.Value, w interface{}) (err error) {
290 ew, ewok := w.(EnterExitWalker) 344 ew, ewok := w.(EnterExitWalker)
291 if ewok { 345 if ewok {
292 ew.Enter(Struct) 346 ew.Enter(Struct)
293 } 347 }
294 348
349 skip := false
295 if sw, ok := w.(StructWalker); ok { 350 if sw, ok := w.(StructWalker); ok {
296 if err = sw.Struct(v); err != nil { 351 err = sw.Struct(v)
352 if err == SkipEntry {
353 skip = true
354 err = nil
355 }
356 if err != nil {
297 return 357 return
298 } 358 }
299 } 359 }
300 360
301 vt := v.Type() 361 if !skip {
302 for i := 0; i < vt.NumField(); i++ { 362 vt := v.Type()
303 sf := vt.Field(i) 363 for i := 0; i < vt.NumField(); i++ {
304 f := v.FieldByIndex([]int{i}) 364 sf := vt.Field(i)
365 f := v.FieldByIndex([]int{i})
305 366
306 if sw, ok := w.(StructWalker); ok { 367 if sw, ok := w.(StructWalker); ok {
307 err = sw.StructField(sf, f) 368 err = sw.StructField(sf, f)
308 369
309 // SkipEntry just pretends this field doesn't even exist 370 // SkipEntry just pretends this field doesn't even exist
310 if err == SkipEntry { 371 if err == SkipEntry {
311 continue 372 continue
373 }
374
375 if err != nil {
376 return
377 }
378 }
379
380 ew, ok := w.(EnterExitWalker)
381 if ok {
382 ew.Enter(StructField)
312 } 383 }
313 384
385 err = walk(f, w)
314 if err != nil { 386 if err != nil {
315 return 387 return
316 } 388 }
317 }
318
319 ew, ok := w.(EnterExitWalker)
320 if ok {
321 ew.Enter(StructField)
322 }
323 389
324 err = walk(f, w) 390 if ok {
325 if err != nil { 391 ew.Exit(StructField)
326 return 392 }
327 }
328
329 if ok {
330 ew.Exit(StructField)
331 } 393 }
332 } 394 }
333 395