@cryptotaxi247 / kubo / commits / 4c5803a3f

coreapi name: add some missing options

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@0ad4722d65f9b8a3021320835291d2161091fd63 This commit was moved from ipfs/boxo@34497dfcf9b4083f51925ee9e7b9ccd14c8f69ce

Łukasz Magiera committed Oct 4, 2018 at 22:11 UTC 4c5803a3f45eb4c1ae769b0ffe0b4fc2f4300404
1 file changed +24
core/coreiface/options/name.go
+24
@@ -13,6 +13,10 @@ const (
13 type NamePublishSettings struct {
14 ValidTime time.Duration
15 Key string
16 +
17 + TTL *time.Duration
18 +
19 + AllowOffline bool
20 }
21
22 type NameResolveSettings struct {
@@ -29,6 +33,8 @@ func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error)
33 options := &NamePublishSettings{
34 ValidTime: DefaultNameValidTime,
35 Key: "self",
36 +
37 + AllowOffline: false,
38 }
39
40 for _, opt := range opts {
@@ -82,6 +88,24 @@ func (nameOpts) Key(key string) NamePublishOption {
88 }
89 }
90
91 +// AllowOffline is an option for Name.Publish which specifies whether to allow
92 +// publishing when the node is offline. Default value is false
93 +func (nameOpts) AllowOffline(allow bool) NamePublishOption {
94 + return func(settings *NamePublishSettings) error {
95 + settings.AllowOffline = allow
96 + return nil
97 + }
98 +}
99 +
100 +// TTL is an option for Name.Publish which specifies the time duration the
101 +// published record should be cached for (caution: experimental).
102 +func (nameOpts) TTL(ttl time.Duration) NamePublishOption {
103 + return func(settings *NamePublishSettings) error {
104 + settings.TTL = &ttl
105 + return nil
106 + }
107 +}
108 +
109 // Local is an option for Name.Resolve which specifies if the lookup should be
110 // offline. Default value is false
111 func (nameOpts) Local(local bool) NameResolveOption {