August 2019
Beginner to intermediate
798 pages
17h 2m
English
The reflectwalk library allows you to walk complex values in Go using reflection in a way that is similar to the way you walk a filesystem. The following example, which is going to walk a structure, is called walkRef.go and it is going to be presented in five parts.
The first part of walkRef.go is as follows:
package main
import (
"fmt"
"github.com/mitchellh/reflectwalk"
"reflect"
)
type Values struct {
Extra map[string]string
}
As reflectwalk is not a standard Go package, you will need to call it using its full address.
The second part of walkRef.go is as follows:
type WalkMap struct { MapVal reflect.Value Keys map[string]bool Values map[string]bool } func (t *WalkMap) Map(m reflect.Value) error { t.MapVal = m return ...Read now
Unlock full access