Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Enter/Exit location for a map in general
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jun 11, 2014
1 parent 67a182b commit 0052d08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions reflectwalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Location uint

const (
None Location = iota
Map
MapKey
MapValue
SliceElem
Expand Down Expand Up @@ -115,6 +116,11 @@ func walk(v reflect.Value, w interface{}) error {
}

func walkMap(v reflect.Value, w interface{}) error {
ew, ewok := w.(EnterExitWalker)
if ewok {
ew.Enter(Map)
}

for _, k := range v.MapKeys() {
kv := v.MapIndex(k)

Expand Down Expand Up @@ -147,6 +153,10 @@ func walkMap(v reflect.Value, w interface{}) error {
}
}

if ewok {
ew.Exit(Map)
}

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions reflectwalk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ func TestWalk_EnterExit(t *testing.T) {
StructField,
StructField,
StructField,
Map,
MapKey,
MapKey,
MapValue,
MapValue,
Map,
StructField,
WalkLoc,
}
Expand Down

0 comments on commit 0052d08

Please sign in to comment.