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

Commit

Permalink
feat: add namesys publish options
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Jan 24, 2023
1 parent 4706f25 commit 8e5d734
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions options/namesys/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,48 @@ func ProcessOpts(opts []ResolveOpt) ResolveOpts {
}
return rsopts
}

// defaultRecordEOL specifies the time that the network will cache IPNS
// records after being published. Records should be re-published before this
// interval expires. We use the same default expiration as the DHT.
const defaultRecordEOL = 48 * time.Hour

// PublishOptions specifies options for publishing an IPNS record.
type PublishOptions struct {
EOL time.Time
TTL time.Duration
}

// DefaultPublishOptions returns the default options for publishing an IPNS record.
func DefaultPublishOptions() PublishOptions {
return PublishOptions{
EOL: time.Now().Add(defaultRecordEOL),
TTL: time.Minute,
}
}

// PublishOption is used to set an option for PublishOpts.
type PublishOption func(*PublishOptions)

// PublishWithEOL sets an EOL.
func PublishWithEOL(eol time.Time) PublishOption {
return func(o *PublishOptions) {
o.EOL = eol
}
}

// PublishWithEOL sets a TTL.
func PublishWithTTL(ttl time.Duration) PublishOption {
return func(o *PublishOptions) {
o.TTL = ttl
}
}

// ProcessPublishOptions converts an array of PublishOpt into a PublishOpts object.
func ProcessPublishOptions(opts []PublishOption) PublishOptions {
rsopts := DefaultPublishOptions()
for _, option := range opts {
option(&rsopts)
}
return rsopts
}

0 comments on commit 8e5d734

Please sign in to comment.