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-dms3
Commits
8d7850ee
Commit
8d7850ee
authored
Oct 21, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated datastore (keytransform)
parent
f7c1ed39
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
core/datastore.go
core/datastore.go
+1
-1
util/key.go
util/key.go
+12
-6
No files found.
core/datastore.go
View file @
8d7850ee
...
...
@@ -31,7 +31,7 @@ func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
if
err
!=
nil
{
return
nil
,
err
}
ktd
:=
ktds
.
Wrap
Datastore
(
d
,
u
.
DsKeyB58Encode
)
ktd
:=
ktds
.
Wrap
(
d
,
u
.
B58KeyConverter
)
return
syncds
.
MutexWrap
(
ktd
),
nil
}
...
...
util/key.go
View file @
8d7850ee
...
...
@@ -29,24 +29,30 @@ func KeyFromDsKey(dsk ds.Key) Key {
return
Key
(
dsk
.
BaseNamespace
())
}
// DsKeyB58Encode returns a B58 encoded Datastore key
// B58KeyConverter -- for KeyTransform datastores
// (static as only one obj needed)
var
B58KeyConverter
=
b58KeyConverter
{}
type
b58KeyConverter
struct
{}
// ConvertKey returns a B58 encoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func
DsKeyB58Encode
(
dsk
ds
.
Key
)
ds
.
Key
{
func
(
b58KeyConverter
)
ConvertKey
(
dsk
ds
.
Key
)
ds
.
Key
{
k
:=
ds
.
NewKey
(
"/"
)
for
_
,
n
:=
range
dsk
.
Namespaces
()
{
k
=
k
.
Child
(
b58
.
Encode
([]
byte
(
n
)))
k
=
k
.
Child
String
(
b58
.
Encode
([]
byte
(
n
)))
}
return
k
}
//
DsKeyB58Decode
returns a b58 decoded Datastore key
//
InvertKey
returns a b58 decoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func
DsKeyB58Decode
(
dsk
ds
.
Key
)
ds
.
Key
{
func
(
b58KeyConverter
)
InvertKey
(
dsk
ds
.
Key
)
ds
.
Key
{
k
:=
ds
.
NewKey
(
"/"
)
for
_
,
n
:=
range
dsk
.
Namespaces
()
{
k
=
k
.
Child
(
string
(
b58
.
Decode
(
n
)))
k
=
k
.
Child
String
(
string
(
b58
.
Decode
(
n
)))
}
return
k
}
...
...
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