walk

package
v0.3.164 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(x any, f WalkFunc) error

Walk through x recursively (using reflection), and apply f to each node. In detail, this means:

  • slices,arrays and maps will be traversed element by element (note that the order is not predictable in case of maps)
  • structs will be traversed field by field (only exported fields)
  • the traversal happens in depth-first order, and the callback is called for each node before traversing its children (i.e. pre-order traversal).

The walk function will be supplied with the following input:

  • pointer nodes will be passed as such
  • non-pointer nodes which are addressable will be passed as pointer to the node
  • other nodes (e.g. non-pointer map entries) will be passed as such
  • path is a string slice describing the path in the tree from root to node; map keys and struct fields as they are, slice/array indices converted to string
  • tag is the struct tag of the most recent struct field seen while traversing.

Notes:

  • Walk may panic in certain situations, e.g. if it is passed non-pointer or nil pointer, or if an unsupported value is encountered while traversing (e.g. a channel)
  • Walk does not produce any errors by itself, it just wraps errors returned by the given callback function f.

Types

type WalkFunc

type WalkFunc func(x any, path []string, tag reflect.StructTag) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL