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
interface-go-dms3-core
Commits
68340710
Commit
68340710
authored
Aug 15, 2018
by
Łukasz Magiera
Committed by
Steven Allen
Aug 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi: block: move option logic to options package
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
f9d6dcc4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
5 deletions
+39
-5
options/block.go
options/block.go
+39
-5
No files found.
options/block.go
View file @
68340710
package
options
import
(
"gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
"fmt"
mh
"gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
cid
"gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
)
type
BlockPutSettings
struct
{
...
...
@@ -17,20 +19,52 @@ type BlockRmSettings struct {
type
BlockPutOption
func
(
*
BlockPutSettings
)
error
type
BlockRmOption
func
(
*
BlockRmSettings
)
error
func
BlockPutOptions
(
opts
...
BlockPutOption
)
(
*
BlockPutSettings
,
error
)
{
func
BlockPutOptions
(
opts
...
BlockPutOption
)
(
*
BlockPutSettings
,
cid
.
Prefix
,
error
)
{
options
:=
&
BlockPutSettings
{
Codec
:
""
,
MhType
:
m
ultihas
h
.
SHA2_256
,
MhType
:
mh
.
SHA2_256
,
MhLength
:
-
1
,
}
for
_
,
opt
:=
range
opts
{
err
:=
opt
(
options
)
if
err
!=
nil
{
return
nil
,
err
return
nil
,
cid
.
Prefix
{},
err
}
}
return
options
,
nil
var
pref
cid
.
Prefix
pref
.
Version
=
1
if
options
.
Codec
==
""
{
if
options
.
MhType
!=
mh
.
SHA2_256
||
(
options
.
MhLength
!=
-
1
&&
options
.
MhLength
!=
32
)
{
options
.
Codec
=
"protobuf"
}
else
{
options
.
Codec
=
"v0"
}
}
if
options
.
Codec
==
"v0"
&&
options
.
MhType
==
mh
.
SHA2_256
{
pref
.
Version
=
0
}
formatval
,
ok
:=
cid
.
Codecs
[
options
.
Codec
]
if
!
ok
{
return
nil
,
cid
.
Prefix
{},
fmt
.
Errorf
(
"unrecognized format: %s"
,
options
.
Codec
)
}
if
options
.
Codec
==
"v0"
{
if
options
.
MhType
!=
mh
.
SHA2_256
||
(
options
.
MhLength
!=
-
1
&&
options
.
MhLength
!=
32
)
{
return
nil
,
cid
.
Prefix
{},
fmt
.
Errorf
(
"only sha2-255-32 is allowed with CIDv0"
)
}
}
pref
.
Codec
=
formatval
pref
.
MhType
=
options
.
MhType
pref
.
MhLength
=
options
.
MhLength
return
options
,
pref
,
nil
}
func
BlockRmOptions
(
opts
...
BlockRmOption
)
(
*
BlockRmSettings
,
error
)
{
...
...
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