![DALL·E 2024-01-10 01 10 19 - the go gopher holding a jar of gochugaru](https://private-user-images.githubusercontent.com/343539/295466170-67bb8a28-d425-472f-96ec-2abbe2982ed2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1OTYzNzgsIm5iZiI6MTczOTU5NjA3OCwicGF0aCI6Ii8zNDM1MzkvMjk1NDY2MTcwLTY3YmI4YTI4LWQ0MjUtNDcyZi05NmVjLTJhYmJlMjk4MmVkMi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNVQwNTA3NThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT04MWI2ZWI0Yzk3Njk3NmI1ZmE3ZGZlYTI2ZTIxZGU0OTQxMTEyM2EzMzRjMjJiZTViMmM1MGJhMWMwZDBjOTkzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.xJSH4XKRzjsvxMvXW7-OQpMjePVvY7jIzOULRT6UwEs)
A SpiceDB client library striving to be as ergonomic as possible.
This library builds upon the official authzed-go library, but tries to expose an interface that guides folks towards optimal performance and correctness.
- ✅ Security-obvious client constructors
- ✅ Defaults to SpiceDB's best compression method
- ✅ Automatic back-off & retry logic
- ✅ Check One/Many/Any/All methods
- ✅ Checks use BulkChecks under the hood
- ✅ Interfaces for Relationships, Objects
- ✅ Flattened Relationship-type with Caveats
- ✅ Transaction-style API for Write
- ✅ Constructors for consistency arguments
- ✅ Callback-style API for Watch and ReadRelationships
- ✅ Atomic and non-atomic Relationship deletion
- 🔜 Keepalives for watch (if necessary)
- ✅ Checks
- ✅ Schema Read/Write
- ✅ Relationship Read/Write/Delete
- 🚧 Import/Export Relationships
- ✅ Watch
- 🔜 Request Debugging
- 🔜 Lookup Resources/Subjects
- 🔜 Reflection APIs
import "github.com/jzelinskie/gochugaru/client"
...
// Various constructors to allocate clients for dev and production environments
// using the best practices.
authz, err := client.NewSystemTLS("spicedb.mycluster.local", presharedKey)
if err != nil {
...
}
import "github.com/jzelinskie/gochugaru/client"
import "github.com/jzelinskie/gochugaru/rel"
...
// Build up a set of relationships to be checked like any other slice.
var founders []Relationship
for _, founder := range []string{"jake", "joey", "jimmy"} {
// There are various constructors for the Relationship type that can
// trade-off allocations for legibility and understandability.
rel, err := rel.FromTriple("company:authzed", "founder", "user:"+founder)
if err != nil {
...
}
founders = append(founders, rel)
}
// Various Check methods can be used to simplify common assertions.
allAreFounders, err := authz.CheckAll(ctx, consistency.MinLatency(), founders...)
if err != nil {
...
} else if !allAreFounders {
...
}
import "github.com/jzelinskie/gochugaru/client"
import "github.com/jzelinskie/gochugaru/rel"
...
// Transactions are built up of preconditions that must or must not exist and
// the set of updates (creates, touches, or deletes) to be applied.
var txn rel.Txn
// The preconditions:
for _, rival := range []string{"joey", "jake"} {
txn.MustNotMatch(rel.MustFromTriple("module:gochugaru", "creator", "user:"+rival).Filter())
}
// The updates:
txn.Touch(rel.MustFromTriple("module:gochugaru", "creator", "user:jimmy"))
txn.Touch(rel.MustFromTriple("module:gochugaru", "maintainer", "sam").
WithCaveat("on_tuesday", map[string]any{"day": "wednesday"}))
writtenAt, err := authz.Write(ctx, txn)
...