pathutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeTypeName

func NormalizeTypeName(typeName string) string

NormalizeTypeName converts Go type strings into user-facing type labels.

Types

type AliasedFacts

type AliasedFacts struct {
	Base    effectus.Facts
	Aliases map[string]string
}

AliasedFacts resolves namespace aliases before delegating to the base facts.

func NewAliasedFacts

func NewAliasedFacts(base effectus.Facts, aliases map[string]string) *AliasedFacts

NewAliasedFacts wraps facts with namespace aliases.

func (*AliasedFacts) Get

func (a *AliasedFacts) Get(path string) (interface{}, bool)

Get returns the value at the resolved path.

func (*AliasedFacts) Schema

func (a *AliasedFacts) Schema() effectus.SchemaInfo

Schema returns the underlying schema info.

type FactLoader

type FactLoader interface {
	Load() (*RegistryFactProvider, error)
}

FactLoader loads data into a registry-backed fact provider.

type FactProvider

type FactProvider interface {
	// Get retrieves a value using a path
	Get(path string) (interface{}, bool)

	// GetWithContext retrieves a value with detailed resolution information
	GetWithContext(path string) (interface{}, *ResolutionResult)
}

FactProvider is an interface for accessing data through paths

type JSONLoader

type JSONLoader struct {
	// contains filtered or unexported fields
}

JSONLoader loads facts from JSON data.

func NewJSONLoader

func NewJSONLoader(jsonData []byte) *JSONLoader

NewJSONLoader creates a new JSON loader.

func (*JSONLoader) Load

func (l *JSONLoader) Load() (*RegistryFactProvider, error)

Load loads JSON data into a registry-backed provider.

type MergeStrategy

type MergeStrategy string

MergeStrategy controls how multiple fact sources are combined.

const (
	MergeFirst MergeStrategy = "first" // highest priority source wins
	MergeLast  MergeStrategy = "last"  // lowest priority source wins
	MergeError MergeStrategy = "error" // error on conflicts
)

type MergedFactProvider

type MergedFactProvider struct {
	// contains filtered or unexported fields
}

MergedFactProvider merges multiple sources for the same namespace.

func NewMergedFactProvider

func NewMergedFactProvider(sources []SourceProvider, strategy MergeStrategy) *MergedFactProvider

NewMergedFactProvider creates a merged provider with the given strategy.

func (*MergedFactProvider) Get

func (m *MergedFactProvider) Get(path string) (interface{}, bool)

Get retrieves a value by applying the merge strategy.

func (*MergedFactProvider) GetWithContext

func (m *MergedFactProvider) GetWithContext(path string) (interface{}, *ResolutionResult)

GetWithContext retrieves a value with resolution context.

type NamespacedLoader

type NamespacedLoader struct {
	// contains filtered or unexported fields
}

NamespacedLoader allows multiple sources to be loaded with different namespaces.

func NewNamespacedLoader

func NewNamespacedLoader() *NamespacedLoader

NewNamespacedLoader creates a new namespaced loader.

func (*NamespacedLoader) AddSource

func (l *NamespacedLoader) AddSource(namespace string, source interface{}) *NamespacedLoader

AddSource adds a data source with a namespace.

func (*NamespacedLoader) Load

Load loads all data sources into a unified provider.

type Path

type Path string

Path is a string using gjson path syntax Examples:

  • "user.profile.name"
  • "posts[0].title"
  • "data.items[2].tags[\"priority\"]"

func (Path) Child

func (p Path) Child(segment string) Path

Child returns a new path by appending a child segment

func (Path) Namespace

func (p Path) Namespace() string

Namespace returns the first segment of the path (before first dot)

func (Path) String

func (p Path) String() string

String returns the path as a string

func (Path) WithNamespace

func (p Path) WithNamespace(namespace string) Path

WithNamespace creates a new path with the specified namespace

type ProtoLoader

type ProtoLoader struct {
	// contains filtered or unexported fields
}

ProtoLoader loads facts from Protocol Buffer messages.

func NewProtoLoader

func NewProtoLoader(message proto.Message) *ProtoLoader

NewProtoLoader creates a new Protocol Buffer loader.

func (*ProtoLoader) Load

func (l *ProtoLoader) Load() (*RegistryFactProvider, error)

Load marshals proto data to JSON and loads it into a provider.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry maintains a mapping from namespaces to fact providers

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new fact provider registry

func (*Registry) Get

func (r *Registry) Get(path string) (interface{}, bool)

Get retrieves a value by routing the request to the appropriate provider

func (*Registry) GetWithContext

func (r *Registry) GetWithContext(path string) (interface{}, *ResolutionResult)

GetWithContext retrieves a value with context by routing to the appropriate provider

func (*Registry) Providers

func (r *Registry) Providers() map[string]FactProvider

Providers returns a shallow copy of registered providers keyed by namespace.

func (*Registry) Register

func (r *Registry) Register(namespace string, provider FactProvider)

Register adds a provider for a specific namespace

type RegistryFactProvider

type RegistryFactProvider struct {
	// contains filtered or unexported fields
}

RegistryFactProvider adapts the schema registry to the pathutil FactProvider interface.

func NewRegistryFactProvider

func NewRegistryFactProvider() *RegistryFactProvider

NewRegistryFactProvider creates a new fact provider using a fresh registry.

func NewRegistryFactProviderFromJSON

func NewRegistryFactProviderFromJSON(jsonData []byte) (*RegistryFactProvider, error)

NewRegistryFactProviderFromJSON loads JSON data into a new registry-backed provider.

func NewRegistryFactProviderFromMap

func NewRegistryFactProviderFromMap(data map[string]interface{}) *RegistryFactProvider

NewRegistryFactProviderFromMap loads a nested map into a new registry-backed provider.

func NewRegistryFactProviderFromStruct

func NewRegistryFactProviderFromStruct(structData interface{}) (*RegistryFactProvider, error)

NewRegistryFactProviderFromStruct converts a struct to a nested map and loads it into a provider.

func NewRegistryFactProviderWithRegistry

func NewRegistryFactProviderWithRegistry(registry *schema.Registry) *RegistryFactProvider

NewRegistryFactProviderWithRegistry creates a provider with an existing registry.

func (*RegistryFactProvider) EvaluateExpr

func (rfp *RegistryFactProvider) EvaluateExpr(expression string) (interface{}, error)

EvaluateExpr is a convenience alias for EvaluateExpression.

func (*RegistryFactProvider) EvaluateExprBool

func (rfp *RegistryFactProvider) EvaluateExprBool(expression string) (bool, error)

EvaluateExprBool evaluates an expression and expects a boolean result.

func (*RegistryFactProvider) EvaluateExpression

func (rfp *RegistryFactProvider) EvaluateExpression(expression string) (interface{}, error)

EvaluateExpression evaluates an expression against the registry.

func (*RegistryFactProvider) Get

func (rfp *RegistryFactProvider) Get(path string) (interface{}, bool)

Get retrieves a value by path.

func (*RegistryFactProvider) GetRegistry

func (rfp *RegistryFactProvider) GetRegistry() *schema.Registry

GetRegistry returns the underlying registry.

func (*RegistryFactProvider) GetWithContext

func (rfp *RegistryFactProvider) GetWithContext(path string) (interface{}, *ResolutionResult)

GetWithContext retrieves a value with resolution context.

func (*RegistryFactProvider) HasPath

func (rfp *RegistryFactProvider) HasPath(path string) bool

HasPath checks if a path exists.

func (*RegistryFactProvider) LoadFromMap

func (rfp *RegistryFactProvider) LoadFromMap(data map[string]interface{})

LoadFromMap merges data into the underlying registry.

func (*RegistryFactProvider) Set

func (rfp *RegistryFactProvider) Set(path string, value interface{})

Set stores a value at a path.

type ResolutionResult

type ResolutionResult struct {
	Path     string      // The original path
	Exists   bool        // Whether the path exists
	Value    interface{} // The resolved value (if exists)
	Error    error       // Error that occurred during resolution (if any)
	Source   string      // Source/provider that resolved the value
	Sources  []string    // All sources that contained the value
	Universe string      // Universe the resolution was scoped to (if any)
}

ResolutionResult contains details about path resolution

type SourceProvider

type SourceProvider struct {
	Name     string
	Provider FactProvider
	Priority int
}

SourceProvider couples a fact provider with a name and priority.

type StructLoader

type StructLoader struct {
	// contains filtered or unexported fields
}

StructLoader loads facts from Go structs.

func NewStructLoader

func NewStructLoader(data interface{}) *StructLoader

NewStructLoader creates a new struct loader.

func (*StructLoader) Load

func (l *StructLoader) Load() (*RegistryFactProvider, error)

Load converts struct data and loads it into a provider.

type UniverseFacts

type UniverseFacts struct {
	Universe string
	Registry *UniverseRegistry
	// contains filtered or unexported fields
}

UniverseFacts scopes fact access to a specific universe.

func NewUniverseFacts

func NewUniverseFacts(registry *UniverseRegistry, universe string, schema effectus.SchemaInfo) *UniverseFacts

NewUniverseFacts creates a facts wrapper for a universe.

func (*UniverseFacts) Get

func (u *UniverseFacts) Get(path string) (interface{}, bool)

Get returns a value within the universe.

func (*UniverseFacts) Schema

func (u *UniverseFacts) Schema() effectus.SchemaInfo

Schema returns the schema for this universe.

type UniverseRegistry

type UniverseRegistry struct {
	// contains filtered or unexported fields
}

UniverseRegistry groups fact providers by universe and namespace.

func NewUniverseRegistry

func NewUniverseRegistry() *UniverseRegistry

NewUniverseRegistry creates an empty universe registry.

func (*UniverseRegistry) Get

func (u *UniverseRegistry) Get(universe, path string) (interface{}, bool)

Get resolves a path within a universe.

func (*UniverseRegistry) GetWithContext

func (u *UniverseRegistry) GetWithContext(universe, path string) (interface{}, *ResolutionResult)

GetWithContext resolves a path within a universe with context.

func (*UniverseRegistry) Register

func (u *UniverseRegistry) Register(universe, namespace string, provider FactProvider)

Register adds a provider for a universe + namespace combination.

func (*UniverseRegistry) RegisterMerged

func (u *UniverseRegistry) RegisterMerged(universe, namespace string, sources []SourceProvider, strategy MergeStrategy)

RegisterMerged registers a merged provider for a universe + namespace.

func (*UniverseRegistry) Universe

func (u *UniverseRegistry) Universe(universe string) *Registry

Universe returns the registry for a given universe.

func (*UniverseRegistry) Universes

func (u *UniverseRegistry) Universes() []string

Universes returns the list of registered universe names.

Jump to

Keyboard shortcuts

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