https://github.com/rlshukhov/storage
Golang storage providers
https://github.com/rlshukhov/storage
badger go golang json storage yaml
Last synced: about 2 months ago
JSON representation
Golang storage providers
- Host: GitHub
- URL: https://github.com/rlshukhov/storage
- Owner: rlshukhov
- License: mpl-2.0
- Created: 2025-01-09T05:10:11.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-22T16:07:50.000Z (over 1 year ago)
- Last Synced: 2025-08-01T00:29:37.172Z (11 months ago)
- Topics: badger, go, golang, json, storage, yaml
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/rlshukhov/storage/actions/workflows/tests.yml)
# Storage
Golang storage providers
## Install
```shell
go get github.com/rlshukhov/storage
```
## Example
```go
package main
import (
"fmt"
"github.com/rlshukhov/nullable"
"github.com/rlshukhov/storage"
"github.com/rlshukhov/storage/file"
)
type User struct {
ID uint64 `yaml:"id"`
Name string `yaml:"name"`
}
func main() {
db, err := storage.GetKeyValueProviderFromConfig[uint64, User](storage.KeyValueConfig{
File: nullable.FromValue(file.Config{
Path: "./users.yaml",
}),
})
if err != nil {
panic(err)
}
err = db.Setup()
if err != nil {
panic(err)
}
defer func() {
err := db.Shutdown()
if err != nil {
panic(err)
}
}()
users := []User{
{ID: 0, Name: "John"},
{ID: 1, Name: "Paul"},
}
for _, user := range users {
err := db.Store(user.ID, user)
if err != nil {
panic(err)
}
}
fmt.Println(db.Get(1))
}
```
```shell
rlshukhov@MacBook-Pro-Lane main % go run main.go
{1 Paul}
rlshukhov@MacBook-Pro-Lane main % cat users.yaml
data:
0:
id: 0
name: John
1:
id: 1
name: Paul
```