walk

package
v1.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 8 Imported by: 2 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

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