Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit 468dea4

Browse files
authored
feat: add namesys publish options (#94)
* feat: add namesys publish options * feat: export DefaultIPNSRecordEOL * feat: export DefaultIPNSRecordTTL
1 parent 4706f25 commit 468dea4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

options/namesys/opts.go

+49
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ const (
1313
// trust resolution to eventually complete and can't put an upper
1414
// limit on how many steps it will take.
1515
UnlimitedDepth = 0
16+
17+
// DefaultIPNSRecordTTL specifies the time that the record can be cached
18+
// before checking if its validity again.
19+
DefaultIPNSRecordTTL = time.Minute
20+
21+
// DefaultIPNSRecordEOL specifies the time that the network will cache IPNS
22+
// records after being published. Records should be re-published before this
23+
// interval expires. We use the same default expiration as the DHT.
24+
DefaultIPNSRecordEOL = 48 * time.Hour
1625
)
1726

1827
// ResolveOpts specifies options for resolving an IPNS path
@@ -72,3 +81,43 @@ func ProcessOpts(opts []ResolveOpt) ResolveOpts {
7281
}
7382
return rsopts
7483
}
84+
85+
// PublishOptions specifies options for publishing an IPNS record.
86+
type PublishOptions struct {
87+
EOL time.Time
88+
TTL time.Duration
89+
}
90+
91+
// DefaultPublishOptions returns the default options for publishing an IPNS record.
92+
func DefaultPublishOptions() PublishOptions {
93+
return PublishOptions{
94+
EOL: time.Now().Add(DefaultIPNSRecordEOL),
95+
TTL: DefaultIPNSRecordTTL,
96+
}
97+
}
98+
99+
// PublishOption is used to set an option for PublishOpts.
100+
type PublishOption func(*PublishOptions)
101+
102+
// PublishWithEOL sets an EOL.
103+
func PublishWithEOL(eol time.Time) PublishOption {
104+
return func(o *PublishOptions) {
105+
o.EOL = eol
106+
}
107+
}
108+
109+
// PublishWithEOL sets a TTL.
110+
func PublishWithTTL(ttl time.Duration) PublishOption {
111+
return func(o *PublishOptions) {
112+
o.TTL = ttl
113+
}
114+
}
115+
116+
// ProcessPublishOptions converts an array of PublishOpt into a PublishOpts object.
117+
func ProcessPublishOptions(opts []PublishOption) PublishOptions {
118+
rsopts := DefaultPublishOptions()
119+
for _, option := range opts {
120+
option(&rsopts)
121+
}
122+
return rsopts
123+
}

0 commit comments

Comments
 (0)