Help us shape the future of Go! Take the 2026 Go Developer Survey

walk

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrTerminate is a sentinel error that can be returned from a MatchFunc to detect when to terminate the walk.
	// When used with the iterator API, users can check for this error and break out of the for loop.
	ErrTerminate = errors.Error("terminate")
)

Variables

This section is empty.

Functions

func SetAtLocation added in v1.6.0

func SetAtLocation[T any](parent any, l LocationContext[T], value any) error

Types

type LocationContext

type LocationContext[T any] struct {
	ParentMatchFunc T
	ParentField     string
	ParentKey       *string
	ParentIndex     *int
}

LocationContext represents the context of where an element is located within its parent. It uses generics to work with different MatchFunc types from different packages.

type Locations

type Locations[T any] []LocationContext[T]

Locations represents a slice of location contexts that can be converted to a JSON pointer.

func (Locations[T]) IsParent added in v1.16.0

func (l Locations[T]) IsParent(field string) bool

IsParent checks if the immediate parent field matches the given field name. It handles both direct struct fields and map/slice items.

func (Locations[T]) ParentKey added in v1.16.0

func (l Locations[T]) ParentKey() string

ParentKey returns the key of the current item if it is in a map. Returns empty string if not in a map or key is nil.

func (Locations[T]) ToJSONPointer

func (l Locations[T]) ToJSONPointer() jsonpointer.JSONPointer

ToJSONPointer converts the locations to a JSON pointer.

Jump to

Keyboard shortcuts

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