typeinfo

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package typeinfo provides a single, cached reflect.Type walker for FastConf's per-T metadata extraction (secret paths, default tags, top-level field hashers). It is the canonical home of FieldName(), the json/yaml/lower(field) tag resolution previously duplicated in core_secret.go and core_watch.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldName

func FieldName(f reflect.StructField) string

FieldName returns the canonical FastConf name for a struct field: json tag → yaml tag → lower(name). Anonymous fields with no tag return the empty string so callers can flatten the path.

func Walk

func Walk(t reflect.Type, v Visitor)

Walk traverses t depth-first, invoking v on every exported field. Pointer indirection and anonymous embedding are flattened transparently; slice/map element types are descended only if they (after pointer elision) are structs.

Types

type Cache

type Cache[V any] struct {
	// contains filtered or unexported fields
}

Cache offers a per-Type, per-Visitor-key result cache so callers (secretPathsFor, planForType, buildFieldHashers) can each maintain their own answer set without re-walking the type on every reload.

func NewCache

func NewCache[V any]() *Cache[V]

NewCache creates a new Cache.

func (*Cache[V]) GetOrCompute

func (c *Cache[V]) GetOrCompute(t reflect.Type, fn func() V) V

GetOrCompute returns the cached value for t or computes it via fn. fn runs while the cache lock is held, so it must be deterministic and must not call GetOrCompute on the same Cache.

type Visitor

type Visitor interface {
	// OnField fires once per exported struct field (including those reached
	// through anonymous embeds), with the dotted JSON path, field index
	// path, and the StructField itself. Return false to skip descending
	// into this field's sub-tree.
	OnField(path string, index []int, f reflect.StructField) bool
	// OnStructEnter fires before descending into a struct type.
	// Return false to skip the entire struct.
	OnStructEnter(path string, t reflect.Type) bool
	// OnStructLeave fires after all fields of a struct have been visited.
	OnStructLeave(path string, t reflect.Type)
}

Visitor receives per-field callbacks during Walk.

type WalkFunc

type WalkFunc func(path string, idx []int, f reflect.StructField, st *reflect.Type) bool

WalkFunc adapts a free function into Visitor when only per-field callbacks are needed.

func (WalkFunc) OnField

func (fn WalkFunc) OnField(path string, idx []int, f reflect.StructField) bool

OnField implements Visitor.

func (WalkFunc) OnStructEnter

func (WalkFunc) OnStructEnter(string, reflect.Type) bool

OnStructEnter implements Visitor.

func (WalkFunc) OnStructLeave

func (WalkFunc) OnStructLeave(string, reflect.Type)

OnStructLeave implements Visitor.

Jump to

Keyboard shortcuts

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