diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..008272a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,18 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + commit-message: + prefix: "deps:" + directory: "/" + schedule: + interval: "weekly" + day: "sunday" + time: "09:00" + - package-ecosystem: "github-actions" + commit-message: + prefix: "ci:" + directory: "/" + schedule: + interval: "weekly" + day: "sunday" + time: "09:00" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..fe37961 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,17 @@ +name: build + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: '0 0 * * 0' # run "At 00:00 on Sunday" + +# See https://github.com/cristalhq/.github/ +jobs: + build: + uses: cristalhq/.github/.github/workflows/build.yml@v0.6.0 + + vuln: + uses: cristalhq/.github/.github/workflows/vuln.yml@v0.6.0 diff --git a/GUIDE.md b/GUIDE.md new file mode 100644 index 0000000..b9b3feb --- /dev/null +++ b/GUIDE.md @@ -0,0 +1 @@ +# Guide for kvstore diff --git a/README.md b/README.md index 01636bc..baab787 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,41 @@ # kvstore -Key-value store abstraction in Go + +[![build-img]][build-url] +[![pkg-img]][pkg-url] +[![version-img]][version-url] + +Key-value store abstraction in Go. + +## Features + +* Simple. +* Dependency-free. + +See [docs][pkg-url] and [GUIDE.md](https://github.com/go-distsys/kvstore/blob/main/GUIDE.md) for more details. + +## Install + +Go version 1.18+ + +``` +go get github.com/go-distsys/kvstore +``` + +## Example + +```go +TODO +``` + +See [example_test.go](https://github.com/go-distsys/kvstore/blob/main/example_test.go). + +## License + +[MIT License](LICENSE). + +[build-img]: https://github.com/go-distsys/kvstore/workflows/build/badge.svg +[build-url]: https://github.com/go-distsys/kvstore/actions +[pkg-img]: https://pkg.go.dev/badge/go-distsys/kvstore +[pkg-url]: https://pkg.go.dev/github.com/go-distsys/kvstore +[version-img]: https://img.shields.io/github/v/release/go-distsys/kvstore +[version-url]: https://github.com/go-distsys/kvstore/releases diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a4a02d6 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/go-distsys/kvstore + +go 1.18 diff --git a/kvstore.go b/kvstore.go new file mode 100644 index 0000000..eed3fd0 --- /dev/null +++ b/kvstore.go @@ -0,0 +1,38 @@ +package kvstore + +import ( + "context" + "errors" +) + +// Store represents the key-value storage. +type Store interface { + Put(ctx context.Context, key string, value []byte) error + Get(ctx context.Context, key string) (*Pair, error) + Delete(ctx context.Context, key string) error + Exists(ctx context.Context, key string) (bool, error) +} + +// AtomicStore represents the key-value storage that supports atomic operations. +type AtomicStore interface { + AtomicPut(ctx context.Context, key string, value []byte, prev *Pair) (bool, *Pair, error) + AtomicGet(ctx context.Context, key string) (*Pair, error) + AtomicDelete(ctx context.Context, key string, prev *Pair) (bool, error) +} + +// WatchStore represents the key-value storage that supports watch operations. +type WatchStore interface { + Watch(ctx context.Context, key string) (<-chan *Pair, error) + WatchTree(ctx context.Context, prefix string) (<-chan []*Pair, error) +} + +// Pair stored in key-value storage. +type Pair struct { + Key string + Value []byte +} + +// Key-value storage errors. +var ( + ErrKeyNotFound = errors.New("key not found") +)