https://github.com/brandonkramer/registry
Thread-safe generic name registry with optional validation, key extraction, and duplicate policy.
https://github.com/brandonkramer/registry
generics go golang library registry
Last synced: 16 days ago
JSON representation
Thread-safe generic name registry with optional validation, key extraction, and duplicate policy.
- Host: GitHub
- URL: https://github.com/brandonkramer/registry
- Owner: brandonkramer
- License: mit
- Created: 2026-05-31T16:54:05.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-05-31T16:56:36.000Z (about 1 month ago)
- Last Synced: 2026-05-31T18:25:26.809Z (about 1 month ago)
- Topics: generics, go, golang, library, registry
- Language: Go
- Size: 50.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# registry
Thread-safe generic name registry with optional validation, key extraction, and duplicate policy.
## Quick start
```go
reg := registry.New[Plugin](
registry.WithValidator(func(p Plugin) error {
if p.Name == "" {
return fmt.Errorf("empty name")
}
return nil
}),
registry.WithKeyFrom(func(p Plugin) string { return p.Name }),
)
reg.MustRegisterItem(Plugin{Name: "alpha"})
p, err := reg.Get("alpha")
if errors.Is(err, registry.ErrNotFound) {
// unknown name
}
snap := reg.Snapshot() // safe map copy for iteration
```
## Options
| Option | Effect |
|--------|--------|
| `WithValidator(fn)` | Validate before register |
| `WithKeyFrom(fn)` | Enable `RegisterItem` / `MustRegisterItem` |
| `WithRejectDuplicates()` | `Register` returns `ErrExists` instead of replacing |
By default, registering the same name **replaces** the previous value.