Browse Source

Add license, readme, and docs

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main v0.0.2
jolheiser 1 year ago
parent
commit
8f41477329
No known key found for this signature in database GPG Key ID: 83E486E71AFEB820
  1. 20
      LICENSE
  2. 9
      README.md
  3. 60
      example_test.go
  4. 21
      store_test.go

20
LICENSE

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2020 John Olheiser
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

9
README.md

@ -0,0 +1,9 @@
# Shock
A wrapper around BBolt.
Check out the [docs](https://pkg.go.dev/go.jolheiser.com/shock).
## License
[MIT](LICENSE)

60
example_test.go

@ -0,0 +1,60 @@
package shock
import (
"fmt"
"io/ioutil"
"os"
"path"
)
// Test object, perhaps a User
type Test struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Age int `json:"age"`
Admin bool `json:"admin"`
}
// Implement the interface for Sequencer
func (t *Test) AssignSeq(seq uint64) {
t.ID = seq
}
func Example() {
dir, err := ioutil.TempDir(os.TempDir(), "shock")
if err != nil {
panic(err)
}
dbPath := path.Join(dir, "shock.db")
db, err = Open(dbPath, os.ModePerm, DefaultOptions)
if err != nil {
panic(err)
}
// Get a bucket to work with instead of specifying each time
bucket := db.Bucket("test")
// Add a new Test user
t := &Test{
Name: "Tester123",
Age: 25,
Admin: true,
}
if err := bucket.Put(t); err != nil {
panic(err)
}
// Get the Test user from the DB later (via sequence ID)
var tt Test
if err := bucket.Get(t.ID, &tt); err != nil {
panic(err)
}
if err := db.Bolt.Close(); err != nil {
fmt.Printf("Could not close DB %s: %v\n", dbPath, err)
}
if err := os.RemoveAll(dir); err != nil {
fmt.Printf("Could not delete temp dir %s: %v\n", dir, err)
}
}

21
store_test.go

@ -4,22 +4,6 @@ import (
"testing"
)
type Test struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Age int `json:"age"`
Admin bool `json:"admin"`
}
func (t *Test) AssignSeq(seq uint64) {
t.ID = seq
}
func (t Test) Equal(tt Test) bool {
return t.ID == tt.ID && t.Name == tt.Name &&
t.Age == tt.Age && t.Admin == tt.Admin
}
func TestStore(t *testing.T) {
tt := []*Test{
@ -97,3 +81,8 @@ func TestStore(t *testing.T) {
}
})
}
func (t Test) Equal(tt Test) bool {
return t.ID == tt.ID && t.Name == tt.Name &&
t.Age == tt.Age && t.Admin == tt.Admin
}

Loading…
Cancel
Save