Commit 3b4b26de authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi: Object api review

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 52f5b7ce
......@@ -193,14 +193,18 @@ type KeyAPI interface {
//TODO: Should this use paths instead of cids?
type ObjectAPI interface {
New(ctx context.Context) (Node, error)
Put(context.Context, Node) error
New(context.Context, ...options.ObjectNewOption) (Node, error)
WithType(string) options.ObjectNewOption
Put(context.Context, Node) (Path, error)
Get(context.Context, Path) (Node, error)
Data(context.Context, Path) (io.Reader, error)
Links(context.Context, Path) ([]*Link, error)
Stat(context.Context, Path) (*ObjectStat, error)
AddLink(ctx context.Context, base Path, name string, child Path, create bool) (Node, error) //TODO: make create optional
AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (Node, error)
WithCreate(create bool) options.ObjectAddLinkOption
RmLink(context.Context, Path, string) (Node, error)
AppendData(context.Context, Path, io.Reader) (Node, error)
SetData(context.Context, Path, io.Reader) (Node, error)
......
package options
type ObjectNewSettings struct {
Type string
}
type ObjectAddLinkSettings struct {
Create bool
}
type ObjectNewOption func(*ObjectNewSettings) error
type ObjectAddLinkOption func(*ObjectAddLinkSettings) error
func ObjectNewOptions(opts ...ObjectNewOption) (*ObjectNewSettings, error) {
options := &ObjectNewSettings{
Type: "empty",
}
for _, opt := range opts {
err := opt(options)
if err != nil {
return nil, err
}
}
return options, nil
}
func ObjectAddLinkOptions(opts ...ObjectAddLinkOption) (*ObjectAddLinkSettings, error) {
options := &ObjectAddLinkSettings{
Create: false,
}
for _, opt := range opts {
err := opt(options)
if err != nil {
return nil, err
}
}
return options, nil
}
type ObjectOptions struct{}
func (api *ObjectOptions) WithType(t string) ObjectNewOption {
return func(settings *ObjectNewSettings) error {
settings.Type = t
return nil
}
}
func (api *ObjectOptions) WithCreate(create bool) ObjectAddLinkOption {
return func(settings *ObjectAddLinkSettings) error {
settings.Create = create
return nil
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment