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-datastore
Commits
da593f50
Commit
da593f50
authored
Oct 20, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added panic datastore
parent
cfbd2baf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
panic/panic.go
panic/panic.go
+67
-0
No files found.
panic/panic.go
0 → 100644
View file @
da593f50
package
sync
import
(
"fmt"
"os"
ds
"github.com/jbenet/datastore.go"
)
type
datastore
struct
{
child
ds
.
Datastore
}
// Wrap shims a datastore such than _any_ operation failing triggers a panic
// This is useful for debugging invariants.
func
Wrap
(
d
ds
.
Datastore
)
ds
.
Shim
{
return
&
datastore
{
child
:
d
}
}
func
(
d
*
datastore
)
Children
()
[]
ds
.
Datastore
{
return
[]
ds
.
Datastore
{
d
.
child
}
}
func
(
d
*
datastore
)
Put
(
key
ds
.
Key
,
value
interface
{})
error
{
err
:=
d
.
child
.
Put
(
key
,
value
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stdout
,
"panic datastore: %s"
,
err
)
panic
(
"panic datastore: Put failed"
)
}
return
nil
}
func
(
d
*
datastore
)
Get
(
key
ds
.
Key
)
(
interface
{},
error
)
{
val
,
err
:=
d
.
child
.
Get
(
key
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stdout
,
"panic datastore: %s"
,
err
)
panic
(
"panic datastore: Get failed"
)
}
return
val
,
nil
}
func
(
d
*
datastore
)
Has
(
key
ds
.
Key
)
(
bool
,
error
)
{
e
,
err
:=
d
.
child
.
Has
(
key
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stdout
,
"panic datastore: %s"
,
err
)
panic
(
"panic datastore: Has failed"
)
}
return
e
,
nil
}
func
(
d
*
datastore
)
Delete
(
key
ds
.
Key
)
error
{
err
:=
d
.
child
.
Delete
(
key
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stdout
,
"panic datastore: %s"
,
err
)
panic
(
"panic datastore: Delete failed"
)
}
return
nil
}
func
(
d
*
datastore
)
KeyList
()
([]
ds
.
Key
,
error
)
{
kl
,
err
:=
d
.
child
.
KeyList
()
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stdout
,
"panic datastore: %s"
,
err
)
panic
(
"panic datastore: KeyList failed"
)
}
return
kl
,
nil
}
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