46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package ironlicensing
|
|
|
|
import "time"
|
|
|
|
// Options configures the IronLicensing client.
|
|
type Options struct {
|
|
PublicKey string
|
|
ProductSlug string
|
|
APIBaseURL string
|
|
Debug bool
|
|
EnableOfflineCache bool
|
|
CacheValidationMinutes int
|
|
OfflineGraceDays int
|
|
HTTPTimeout time.Duration
|
|
}
|
|
|
|
// DefaultOptions returns the default configuration options.
|
|
func DefaultOptions() Options {
|
|
return Options{
|
|
APIBaseURL: "https://api.ironlicensing.com",
|
|
Debug: false,
|
|
EnableOfflineCache: true,
|
|
CacheValidationMinutes: 60,
|
|
OfflineGraceDays: 7,
|
|
HTTPTimeout: 30 * time.Second,
|
|
}
|
|
}
|
|
|
|
// WithDefaults returns the options with default values applied.
|
|
func (o Options) WithDefaults() Options {
|
|
defaults := DefaultOptions()
|
|
if o.APIBaseURL == "" {
|
|
o.APIBaseURL = defaults.APIBaseURL
|
|
}
|
|
if o.CacheValidationMinutes == 0 {
|
|
o.CacheValidationMinutes = defaults.CacheValidationMinutes
|
|
}
|
|
if o.OfflineGraceDays == 0 {
|
|
o.OfflineGraceDays = defaults.OfflineGraceDays
|
|
}
|
|
if o.HTTPTimeout == 0 {
|
|
o.HTTPTimeout = defaults.HTTPTimeout
|
|
}
|
|
return o
|
|
}
|