Skip to content

Instantly share code, notes, and snippets.

View KuthumiPepple's full-sized avatar

Kuthumi Pepple KuthumiPepple

View GitHub Profile
@KuthumiPepple
KuthumiPepple / walk.go
Created April 2, 2022 20:18
Walk function takes a struct and a function as arguments and calls the function for all string fields found inside the struct. The use of reflection is demonstrated here.
package reflection
import "reflect"
func Walk(x interface{}, fn func(input string)) {
val := getValue(x)
walkValue := func(value reflect.Value) {
Walk(value.Interface(), fn)
}