This repository was archived by the owner on Jun 19, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -72,3 +72,48 @@ func ProcessOpts(opts []ResolveOpt) ResolveOpts {
7272 }
7373 return rsopts
7474}
75+
76+ // defaultRecordEOL specifies the time that the network will cache IPNS
77+ // records after being published. Records should be re-published before this
78+ // interval expires.
79+ const defaultRecordEOL = 24 * time .Hour
80+
81+ // PublishOptions specifies options for publishing an IPNS record.
82+ type PublishOptions struct {
83+ EOL time.Time
84+ TTL * time.Duration
85+ }
86+
87+ // DefaultPublishOptions returns the default options for publishing an IPNS record.
88+ func DefaultPublishOptions () PublishOptions {
89+ return PublishOptions {
90+ EOL : time .Now ().Add (defaultRecordEOL ),
91+ TTL : nil ,
92+ }
93+ }
94+
95+ // PublishOption is used to set an option for PublishOpts.
96+ type PublishOption func (* PublishOptions )
97+
98+ // PublishWithEOL sets an EOL.
99+ func PublishWithEOL (eol time.Time ) PublishOption {
100+ return func (o * PublishOptions ) {
101+ o .EOL = eol
102+ }
103+ }
104+
105+ // PublishWithEOL sets a TTL.
106+ func PublishWithTTL (ttl time.Duration ) PublishOption {
107+ return func (o * PublishOptions ) {
108+ o .TTL = & ttl
109+ }
110+ }
111+
112+ // ProcessPublishOptions converts an array of PublishOpt into a PublishOpts object.
113+ func ProcessPublishOptions (opts []PublishOption ) PublishOptions {
114+ rsopts := DefaultPublishOptions ()
115+ for _ , option := range opts {
116+ option (& rsopts )
117+ }
118+ return rsopts
119+ }
You can’t perform that action at this time.
0 commit comments