https://github.com/go-spring/barky
a lightweight library for hierarchical configuration storage and path parsing.
https://github.com/go-spring/barky
Last synced: 10 months ago
JSON representation
a lightweight library for hierarchical configuration storage and path parsing.
- Host: GitHub
- URL: https://github.com/go-spring/barky
- Owner: go-spring
- License: apache-2.0
- Created: 2025-08-15T22:46:09.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-15T23:38:36.000Z (10 months ago)
- Last Synced: 2025-08-16T01:26:59.615Z (10 months ago)
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Barky
[English](README.md) | [δΈζ](README_CN.md)
**Barky** is a lightweight library for **hierarchical configuration storage and path parsing**, inspired by
JSON/YAML/TOML access patterns.
It provides **type-safe path handling**, structured storage, subkey lookup, and conflict detection, making it ideal for
managing nested configuration data.
---
## β¨ Features
* **Path Parsing & Construction**
* `SplitPath`: Parse a string path into structured `Path` segments
* `JoinPath`: Build a string path from structured segments
* **Two Path Types**
* **Key**: For map/object access (e.g., `"user.name"`)
* **Index**: For array/list access (e.g., `"[0]"`)
* **Hierarchical Storage**
* Maintains a tree structure (`treeNode`) for type-safe paths
* Query subkeys with `SubKeys`
* Check if a path exists with `Has`
* Insert key-value pairs with automatic tree building and conflict detection via `Set`
* **Conflict Detection**
* Detects type mismatches (e.g., when a path segment is used both as a key and as an index)
* **File Source Tracking**
* Each value is associated with its source file and a file ID, useful when merging multiple configs
---
## π¦ Installation
```bash
go get github.com/go-spring/barky
```
---
## π Usage Examples
### Path Parsing & Building
```go
path, _ := barky.SplitPath("users[0].profile.name")
// path => [ {Key:"users"}, {Index:"0"}, {Key:"profile"}, {Key:"name"} ]
joined := barky.JoinPath(path)
// joined => "users[0].profile.name"
```
### Storage Operations
```go
s := barky.NewStorage()
fileID := s.AddFile("config.yaml")
// Insert values
s.Set("users[0].profile.name", "Alice", fileID)
s.Set("users[0].profile.age", "30", fileID)
// Check existence
exists := s.Has("users[0].profile.name")
// true
// Get subkeys
subs, _ := s.SubKeys("users[0].profile")
// subs => ["age", "name"]
// Inspect raw storage
raw := s.RawData()
// map["users[0].profile.name"] => ValueInfo{File:0, Value:"Alice"}
```
---
## π Use Cases
* **Configuration Management**
* Load and merge multiple config files (YAML/JSON/TOML)
* Detect and prevent structural conflicts
* **Structured Data Access**
* Safely access nested values with clear key/index separation
* Unified path handling across maps and arrays
* **Validation & Debugging**
* Check if a configuration path exists
* Retrieve all subkeys under a path
---
## β οΈ Notes
* Invalid path formats (spaces, consecutive dots, unclosed brackets, etc.) will return an error
* Structural conflicts (e.g., `"user.name"` vs `"user[0]"`) are detected and rejected
* `RawData` and `RawFile` expose internal state directly β use with caution
---
## π License
Apache 2.0 License