Skip to content

Commit

Permalink
Update documentation (#3)
Browse files Browse the repository at this point in the history
* Update documentation

* Update README.md
  • Loading branch information
lucmq authored Jun 11, 2024
1 parent bd385ca commit d9f6c6a
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ go get github.com/lucmq/go-shelve
```

## Usage
Here are some basic examples of how to use `go-shelve`:
Here are some examples of how to use `go-shelve`:

### Basic
The following example illustrates the usage of a `Shelf` with string keys and
Expand Down Expand Up @@ -56,7 +56,7 @@ func main() {

// Use the database
shelf.Put("language", "Go")
shelf.Put("module", "go-shelve")
shelf.Put("module", "Go-Shelve")

// Note: Saved values will be available between restarts
value, ok, _ := shelf.Get("language")
Expand Down Expand Up @@ -109,7 +109,7 @@ func main() {

// Use the database
shelf.Put("language", "Go")
shelf.Put("module", "go-shelve")
shelf.Put("module", "Go-Shelve")

value, ok, _ := shelf.Get("language")
fmt.Println(value, ok)
Expand Down
10 changes: 5 additions & 5 deletions driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ codecs, meant to be used as part of the go-shelve project.

### Databases:
#### Supported:
- Bolt
- BBolt
- Badger
- Diskv
- [Bolt](https://pkg.go.dev/github.com/lucmq/go-shelve/driver/db/bolt)
- [BBolt](https://pkg.go.dev/github.com/lucmq/go-shelve/driver/db/bboltd)
- [Badger](https://pkg.go.dev/github.com/lucmq/go-shelve/driver/db/badger)
- [Diskv](https://pkg.go.dev/github.com/lucmq/go-shelve/driver/db/diskv)

#### Beta:
- None
Expand All @@ -19,7 +19,7 @@ codecs, meant to be used as part of the go-shelve project.

### Codecs:
#### Supported:
- MessagePack
- [MessagePack](https://pkg.go.dev/github.com/lucmq/go-shelve/driver/encoding/msgpack)

### Beta
- None
Expand Down
6 changes: 5 additions & 1 deletion driver/db/badger/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import (
"slices"

"github.com/dgraph-io/badger/v3"
"github.com/lucmq/go-shelve/shelve"
)

// Store is a BadgerDB driver for go-shelve/Shelf.
// Store is a BadgerDB driver for [shelve.Shelf].
type Store struct {
db *badger.DB
valueCopy copyFunc
}

// Assert Store implements shelve.DB
var _ shelve.DB = (*Store)(nil)

type copyFunc func(item *badger.Item, dest []byte) ([]byte, error)

// New creates a new BadgerDB store.
Expand Down
6 changes: 5 additions & 1 deletion driver/db/bbolt/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import (
"fmt"
"os"

"github.com/lucmq/go-shelve/shelve"
"go.etcd.io/bbolt"
)

// Store is a BoltDB driver for go-shelve/Shelf.
// Store is a BoltDB driver for [shelve.Shelf].
type Store struct {
db *bbolt.DB
bucket []byte
}

// Assert Store implements shelve.DB
var _ shelve.DB = (*Store)(nil)

// New creates a new BoltDB store. The bucket is created if it doesn't exist.
func New(db *bbolt.DB, bucket []byte) (*Store, error) {
err := db.Update(func(tx *bbolt.Tx) error {
Expand Down
6 changes: 5 additions & 1 deletion driver/db/bolt/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import (
"os"

"github.com/boltdb/bolt"
"github.com/lucmq/go-shelve/shelve"
)

// Store is a BoltDB driver for go-shelve/Shelf.
// Store is a BoltDB driver for [shelve.Shelf].
type Store struct {
db *bolt.DB
bucket []byte
}

// Assert Store implements shelve.DB
var _ shelve.DB = (*Store)(nil)

// New creates a new BoltDB store. The bucket is created if it doesn't exist.
func New(db *bolt.DB, bucket []byte) (*Store, error) {
err := db.Update(func(tx *bolt.Tx) error {
Expand Down
2 changes: 1 addition & 1 deletion driver/db/diskv/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type IndexLen interface {
Len() int
}

// Store is a shelve.DB driver backed by a diskv.Diskv instance.
// Store is a [shelve.DB] driver backed by a diskv.Diskv instance.
type Store struct {
db *diskv.Diskv

Expand Down
4 changes: 2 additions & 2 deletions driver/encoding/msgpack/msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/lucmq/go-shelve/shelve"
)

// Codec is a codec for msgpack. Codec implements the shelve.Codec interface.
// Codec is a [shelve.Codec] driver for msgpack.
type Codec struct{}

// Assert Codec implements shelve.Codec
Expand All @@ -18,7 +18,7 @@ func NewDefault() *Codec {
return &Codec{}
}

// Encode returns the msgpack Codec encoding of v as a byte slice.
// Encode returns the msgpack encoding of v as a byte slice.
func (e *Codec) Encode(value any) ([]byte, error) {
return msgpack.Marshal(value)
}
Expand Down
1 change: 1 addition & 0 deletions driver/test/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/lucmq/go-shelve/shelve"
)

// TestError is the error used in tests.
var TestError = errors.New("test error")

// TDB matches the shelve.DB interface.
Expand Down

0 comments on commit d9f6c6a

Please sign in to comment.