-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
14 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
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package store | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/peterbourgon/diskv" | ||
) | ||
|
||
// DiskRepo holds a representation of a persistant store backend | ||
type DiskRepo struct { | ||
d *diskv.Diskv | ||
} | ||
|
||
// NewDiskRepository returns a newly persistant store repository | ||
func NewDiskRepository(path string) (*DiskRepo, error) { | ||
d := diskv.New(diskv.Options{ | ||
BasePath: path, | ||
CacheSizeMax: 1024 * 1024, | ||
}) | ||
|
||
return &DiskRepo{ | ||
d: d, | ||
}, nil | ||
} | ||
|
||
// Save stores a new value for a key in the k/v store | ||
func (r *DiskRepo) Save(key string, value string) error { | ||
if err := r.d.Write(key, []byte(value)); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Get retrieves a value from the k/v store | ||
func (r *DiskRepo) Get(key string) (string, error) { | ||
value, err := r.d.Read(key) | ||
if err != nil { | ||
return "", fmt.Errorf("no value found for key '%s', err: %s", key, err) | ||
} | ||
return string(value), nil | ||
} |
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