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
104bc87d
Commit
104bc87d
authored
Jan 04, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi: implement object.Put
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
55c56578
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
interface.go
interface.go
+13
-2
options/object.go
options/object.go
+26
-0
No files found.
interface.go
View file @
104bc87d
...
@@ -64,6 +64,9 @@ type CoreAPI interface {
...
@@ -64,6 +64,9 @@ type CoreAPI interface {
// Key returns an implementation of Key API.
// Key returns an implementation of Key API.
Key
()
KeyAPI
Key
()
KeyAPI
// ObjectAPI returns an implementation of Object API
Object
()
ObjectAPI
// ResolvePath resolves the path using Unixfs resolver
// ResolvePath resolves the path using Unixfs resolver
ResolvePath
(
context
.
Context
,
Path
)
(
Path
,
error
)
ResolvePath
(
context
.
Context
,
Path
)
(
Path
,
error
)
...
@@ -205,8 +208,16 @@ type ObjectAPI interface {
...
@@ -205,8 +208,16 @@ type ObjectAPI interface {
// * 'unixfs-dir' - Empty UnixFS directory
// * 'unixfs-dir' - Empty UnixFS directory
WithType
(
string
)
options
.
ObjectNewOption
WithType
(
string
)
options
.
ObjectNewOption
// Put imports the node into merkledag
// Put imports the data into merkledag
Put
(
context
.
Context
,
Node
)
(
Path
,
error
)
Put
(
context
.
Context
,
io
.
Reader
,
...
options
.
ObjectPutOption
)
(
Path
,
error
)
// WithInputEnc is an option for Put which specifies the input encoding of the
// data. Default is "json".
//
// Supported encodings:
// * "protobuf"
// * "json"
WithInputEnc
(
e
string
)
options
.
ObjectPutOption
// Get returns the node for the path
// Get returns the node for the path
Get
(
context
.
Context
,
Path
)
(
Node
,
error
)
Get
(
context
.
Context
,
Path
)
(
Node
,
error
)
...
...
options/object.go
View file @
104bc87d
...
@@ -4,11 +4,16 @@ type ObjectNewSettings struct {
...
@@ -4,11 +4,16 @@ type ObjectNewSettings struct {
Type
string
Type
string
}
}
type
ObjectPutSettings
struct
{
InputEnc
string
}
type
ObjectAddLinkSettings
struct
{
type
ObjectAddLinkSettings
struct
{
Create
bool
Create
bool
}
}
type
ObjectNewOption
func
(
*
ObjectNewSettings
)
error
type
ObjectNewOption
func
(
*
ObjectNewSettings
)
error
type
ObjectPutOption
func
(
*
ObjectPutSettings
)
error
type
ObjectAddLinkOption
func
(
*
ObjectAddLinkSettings
)
error
type
ObjectAddLinkOption
func
(
*
ObjectAddLinkSettings
)
error
func
ObjectNewOptions
(
opts
...
ObjectNewOption
)
(
*
ObjectNewSettings
,
error
)
{
func
ObjectNewOptions
(
opts
...
ObjectNewOption
)
(
*
ObjectNewSettings
,
error
)
{
...
@@ -25,6 +30,20 @@ func ObjectNewOptions(opts ...ObjectNewOption) (*ObjectNewSettings, error) {
...
@@ -25,6 +30,20 @@ func ObjectNewOptions(opts ...ObjectNewOption) (*ObjectNewSettings, error) {
return
options
,
nil
return
options
,
nil
}
}
func
ObjectPutOptions
(
opts
...
ObjectPutOption
)
(
*
ObjectPutSettings
,
error
)
{
options
:=
&
ObjectPutSettings
{
InputEnc
:
"json"
,
}
for
_
,
opt
:=
range
opts
{
err
:=
opt
(
options
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
options
,
nil
}
func
ObjectAddLinkOptions
(
opts
...
ObjectAddLinkOption
)
(
*
ObjectAddLinkSettings
,
error
)
{
func
ObjectAddLinkOptions
(
opts
...
ObjectAddLinkOption
)
(
*
ObjectAddLinkSettings
,
error
)
{
options
:=
&
ObjectAddLinkSettings
{
options
:=
&
ObjectAddLinkSettings
{
Create
:
false
,
Create
:
false
,
...
@@ -48,6 +67,13 @@ func (api *ObjectOptions) WithType(t string) ObjectNewOption {
...
@@ -48,6 +67,13 @@ func (api *ObjectOptions) WithType(t string) ObjectNewOption {
}
}
}
}
func
(
api
*
ObjectOptions
)
WithInputEnc
(
e
string
)
ObjectPutOption
{
return
func
(
settings
*
ObjectPutSettings
)
error
{
settings
.
InputEnc
=
e
return
nil
}
}
func
(
api
*
ObjectOptions
)
WithCreate
(
create
bool
)
ObjectAddLinkOption
{
func
(
api
*
ObjectOptions
)
WithCreate
(
create
bool
)
ObjectAddLinkOption
{
return
func
(
settings
*
ObjectAddLinkSettings
)
error
{
return
func
(
settings
*
ObjectAddLinkSettings
)
error
{
settings
.
Create
=
create
settings
.
Create
=
create
...
...
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