An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# Barky


license
go-version
release

test-coverage

Ask DeepWiki

[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