OSDN Git Service

add ipfs package
[bytom/vapor.git] / vendor / github.com / ipfs / go-ipfs-api / options / dag.go
1 package options
2
3 // DagPutSettings is a set of DagPut options.
4 type DagPutSettings struct {
5         InputEnc string
6         Kind     string
7         Pin      string
8 }
9
10 // DagPutOption is a single DagPut option.
11 type DagPutOption func(opts *DagPutSettings) error
12
13 // DagPutOptions applies the given options to a DagPutSettings instance.
14 func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) {
15         options := &DagPutSettings{
16                 InputEnc: "json",
17                 Kind:     "cbor",
18                 Pin:      "false",
19         }
20
21         for _, opt := range opts {
22                 err := opt(options)
23                 if err != nil {
24                         return nil, err
25                 }
26         }
27         return options, nil
28 }
29
30 type dagOpts struct{}
31
32 var Dag dagOpts
33
34 // Pin is an option for Dag.Put which specifies whether to pin the added
35 // dags. Default is "false".
36 func (dagOpts) Pin(pin string) DagPutOption {
37         return func(opts *DagPutSettings) error {
38                 opts.Pin = pin
39                 return nil
40         }
41 }
42
43 // InputEnc is an option for Dag.Put which specifies the input encoding of the
44 // data. Default is "json", most formats/codecs support "raw".
45 func (dagOpts) InputEnc(enc string) DagPutOption {
46         return func(opts *DagPutSettings) error {
47                 opts.InputEnc = enc
48                 return nil
49         }
50 }
51
52 // Kind is an option for Dag.Put which specifies the format that the dag
53 // will be added as. Default is "cbor".
54 func (dagOpts) Kind(kind string) DagPutOption {
55         return func(opts *DagPutSettings) error {
56                 opts.Kind = kind
57                 return nil
58         }
59 }