Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ds-leveldb
Commits
a8f2ca75
Commit
a8f2ca75
authored
Jan 27, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go fmt
parent
4629b043
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
32 deletions
+32
-32
datastore.go
datastore.go
+32
-32
No files found.
datastore.go
View file @
a8f2ca75
package
leveldb
import
(
ds
"github.com/jbenet/datastore.go"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
ds
"github.com/jbenet/datastore.go"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
)
// Datastore uses a standard Go map for internal storage.
type
Datastore
struct
{
DB
*
leveldb
.
DB
DB
*
leveldb
.
DB
}
type
Options
opt
.
Options
func
NewDatastore
(
path
string
,
opts
*
Options
)
(
*
Datastore
,
error
)
{
nopts
:=
opt
.
Options
(
*
opts
)
db
,
err
:=
leveldb
.
OpenFile
(
path
,
&
nopts
)
if
err
!=
nil
{
return
nil
,
err
}
nopts
:=
opt
.
Options
(
*
opts
)
db
,
err
:=
leveldb
.
OpenFile
(
path
,
&
nopts
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
Datastore
{
DB
:
db
,
},
nil
return
&
Datastore
{
DB
:
db
,
},
nil
}
// Returns ErrInvalidType if value is not of type []byte.
...
...
@@ -30,37 +30,37 @@ func NewDatastore(path string, opts *Options) (*Datastore, error) {
// Note: using sync = false.
// see http://godoc.org/github.com/syndtr/goleveldb/leveldb/opt#WriteOptions
func
(
d
*
Datastore
)
Put
(
key
ds
.
Key
,
value
interface
{})
(
err
error
)
{
val
,
failed
:=
value
.
([]
byte
)
if
failed
{
return
ds
.
ErrInvalidType
}
return
d
.
DB
.
Put
(
key
.
Bytes
(),
val
,
nil
)
val
,
failed
:=
value
.
([]
byte
)
if
failed
{
return
ds
.
ErrInvalidType
}
return
d
.
DB
.
Put
(
key
.
Bytes
(),
val
,
nil
)
}
func
(
d
*
Datastore
)
Get
(
key
ds
.
Key
)
(
value
interface
{},
err
error
)
{
val
,
err
:=
d
.
DB
.
Get
(
key
.
Bytes
(),
nil
)
if
err
!=
nil
{
if
err
==
leveldb
.
ErrNotFound
{
return
nil
,
ds
.
ErrNotFound
}
return
nil
,
err
}
return
val
,
nil
val
,
err
:=
d
.
DB
.
Get
(
key
.
Bytes
(),
nil
)
if
err
!=
nil
{
if
err
==
leveldb
.
ErrNotFound
{
return
nil
,
ds
.
ErrNotFound
}
return
nil
,
err
}
return
val
,
nil
}
func
(
d
*
Datastore
)
Has
(
key
ds
.
Key
)
(
exists
bool
,
err
error
)
{
return
ds
.
GetBackedHas
(
d
,
key
)
return
ds
.
GetBackedHas
(
d
,
key
)
}
func
(
d
*
Datastore
)
Delete
(
key
ds
.
Key
)
(
err
error
)
{
err
=
d
.
DB
.
Delete
(
key
.
Bytes
(),
nil
)
if
err
==
leveldb
.
ErrNotFound
{
return
ds
.
ErrNotFound
}
return
err
err
=
d
.
DB
.
Delete
(
key
.
Bytes
(),
nil
)
if
err
==
leveldb
.
ErrNotFound
{
return
ds
.
ErrNotFound
}
return
err
}
// LevelDB needs to be closed.
func
(
d
*
Datastore
)
Close
()
(
err
error
)
{
return
d
.
DB
.
Close
()
return
d
.
DB
.
Close
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment