-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update and complete documentation (#11)
* docs: Fix typos and what not. Signed-off-by: Vaibhav <vrongmeal@gmail.com> * Add favicon and update README Signed-off-by: Vaibhav <vrongmeal@gmail.com> * docs: Add tutorial. Signed-off-by: Vaibhav <vrongmeal@gmail.com> * Fix headings for tutorial and add concepts section. Signed-off-by: Vaibhav <vrongmeal@gmail.com> * docs: Improvements in tutorial. Signed-off-by: Vaibhav <vrongmeal@gmail.com> * docs: Add advanced section. Signed-off-by: Vaibhav <vrongmeal@gmail.com> * docs: Add concepts (store, values and stdkiwi). Signed-off-by: Vaibhav <vrongmeal@gmail.com> * Add contribution guidelines to docs. Signed-off-by: Vaibhav <vrongmeal@gmail.com> * Add docs link to README. Signed-off-by: Vaibhav <vrongmeal@gmail.com> * docs: Add 'new value type' section * docs: Minor changes to docs Signed-off-by: Vaibhav <vrongmeal@gmail.com> * Add badges for gh-actions * Update doc.go Signed-off-by: Vaibhav <vrongmeal@gmail.com> Co-authored-by: murex971 <nupur202000@gmail.com>
- Loading branch information
Showing
20 changed files
with
1,162 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,75 @@ | ||
# kiwi | ||
![Kiwi Logo](./docs/.vuepress/public/kiwi-logo.png) | ||
|
||
> A minimalistic in-memory key value store. | ||
Each key is thread safe as it is protected by its own mutex, though different keys can be accessed by various threads. | ||
![Go CI](https://github.com/sdslabs/kiwi/workflows/Go%20CI/badge.svg) ![Docs CI](https://github.com/sdslabs/kiwi/workflows/Docs%20CI/badge.svg) ![Docs CD](https://github.com/sdslabs/kiwi/workflows/Docs%20CD/badge.svg) | ||
|
||
To get started, create a store with the NewStore function and add keys to it using AddKey. | ||
Each key is associated with a value which has a specific type. | ||
These types are extendible and can be created by implementing the Value interface. | ||
## Overview | ||
|
||
Store can also be initialised with a schema, which is basically a map of keys and value types. | ||
You can think of Kiwi as thread safe global variables. This kind of library | ||
comes in helpful when you need to manage state accross your application which | ||
can be mutated with multiple threads. Kiwi protects your keys with mutex locks | ||
so you don't have to. | ||
|
||
```go | ||
// If you have a pre-defined schema | ||
schema := kiwi.Schema{ | ||
"key1": str.Type, // string key | ||
// ... | ||
} | ||
Head over to [kiwi.sdslabs.co](https://kiwi.sdslabs.co) for more details and | ||
documentation. | ||
|
||
store, err := kiwi.NewStoreFromSchema(schema) | ||
if err != nil { | ||
// handle error | ||
} | ||
## Installation | ||
|
||
// If you want to add/update keys dynamically | ||
store.AddKey("key2", str.Type) | ||
store.UpdateKey("key1", list.Type) | ||
> Kiwi requires [Go](https://golang.org/) >= 1.14 | ||
// Invoke an action, say updating a string | ||
_, err := store.Do("key2", str.Update, "abc") | ||
if err != nil { | ||
// handle error | ||
} | ||
Kiwi can be integrated with your application just like any other go library. | ||
|
||
// or if you need to get the string | ||
s, err := store.Do("key2", str.Get) | ||
if err != nil { | ||
// handle error | ||
} | ||
```sh | ||
go get -u github.com/sdslabs/kiwi | ||
``` | ||
|
||
myString := s.(string) | ||
// use myString | ||
Now you can import kiwi any where in your code. | ||
|
||
```go | ||
import "github.com/sdslabs/kiwi" | ||
``` | ||
|
||
Package `github.com/sdslabs/kiwi/stdkiwi` implements type safe methods with standard types registered. | ||
These types include: | ||
- [x] str (`github.com/sdslabs/kiwi/values/str`): String value | ||
- [x] list (`github.com/sdslabs/kiwi/values/list`): A list of strings | ||
- [x] set (`github.com/sdslabs/kiwi/values/set`): An exclusive set of strings | ||
- [x] hash (`github.com/sdslabs/kiwi/values/hash`): A string-string hashmap | ||
- [x] zset (`github.com/sdslabs/kiwi/values/zset`): A set with each element having scores | ||
## Basic usage | ||
|
||
If you only require the aforementioned value types, use the `stdkiwi` package. | ||
The above example using the `stdkiwi` package is as follows: | ||
Create a store, add key and play with it. It's that easy! | ||
|
||
```go | ||
// If you have a pre-defined schema | ||
schema := kiwi.Schema{ | ||
"key1": str.Type, // string key | ||
// ... | ||
} | ||
store := stdkiwi.NewStore() | ||
|
||
store, err := stdkiwi.NewStoreFromSchema(schema) | ||
if err != nil { | ||
// handle error | ||
if err := store.AddKey("my_string", "str"); err != nil { | ||
// handle error | ||
} | ||
|
||
myString := store.Str("my_string") | ||
|
||
// If you want to add/update keys dynamically | ||
store.AddKey("key2", str.Typ) | ||
store.UpdateKey("key1", list.Typ) | ||
if err := myString.Update("Hello, World!"); err != nil { | ||
// handle error | ||
} | ||
|
||
// Invoke an action, say updating a string | ||
err = store.Str("key2").Update("abc") | ||
str, err := myString.Get() | ||
if err != nil { | ||
// handle error | ||
// handle error | ||
} | ||
|
||
mystring := store.Str("key2").Get() | ||
// use mystring | ||
fmt.Println(str) // Hello, World! | ||
``` | ||
|
||
// If the schema is known while starting the app, to avoid unnecessary errors during app runtime, | ||
// use Guard method for the values when initializing the store. | ||
str.List("key1").Guard() // panics on error | ||
## Contributing | ||
|
||
err = str.Str("key2").GuardE() // returns error | ||
if err != nil { | ||
// handle error | ||
} | ||
``` | ||
We are always open for contributions. If you find any feature missing, or just | ||
want to report a bug, feel free to open an issue and/or submit a pull request | ||
regarding the same. | ||
|
||
For more information on contribution, check out our | ||
[docs](https://kiwi.sdslabs.co/docs/contribution-guide.html). | ||
|
||
## Contact | ||
|
||
If you have a query regarding the product or just want to say hello then feel | ||
free to visit [chat.sdslabs.co](https://chat.sdslabs.co) or drop a mail at | ||
[contact@sdslabs.co.in](mailto:contact@sdslabs.co.in) | ||
|
||
--- | ||
|
||
To implement a custom value, all that is required is to implement the `kiwi.Value` interface and register | ||
it with the kiwi store using `kiwi.RegisterValue`. Look at the `github.com/sdslabs/kiwi/values` for examples. | ||
Made by [SDSLabs](https://sdslabs.co) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ | |
|
||
.home .hero img | ||
max-width 450px!important | ||
|
||
h1#main-title | ||
display none!important |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.