refactor: change the way default values are set in service constructor
This commit is contained in:
parent
336bd34bd3
commit
e8f7a7e329
1 changed files with 12 additions and 9 deletions
|
|
@ -39,27 +39,30 @@ func New(s store.Store, opts Options) (*Service, error) {
|
|||
return nil, errors.New("pase: store is required")
|
||||
}
|
||||
|
||||
if opts.IDGenerator == nil {
|
||||
opts.IDGenerator = DefaultIDGenerator()
|
||||
idGenerator := DefaultIDGenerator()
|
||||
if opts.IDGenerator != nil {
|
||||
idGenerator = opts.IDGenerator
|
||||
}
|
||||
|
||||
operationTimeout := DefaultOperationTimeout
|
||||
if opts.OperationTimeout < 0 {
|
||||
return nil, errors.New("pase: OperationTimeout must be non-negative")
|
||||
} else if opts.OperationTimeout == 0 {
|
||||
opts.OperationTimeout = DefaultOperationTimeout
|
||||
} else if opts.OperationTimeout != 0 {
|
||||
operationTimeout = opts.OperationTimeout
|
||||
}
|
||||
|
||||
magicLinkTTL := DefaultMagicLinkTTL
|
||||
if opts.MagicLinkTTL < 0 {
|
||||
return nil, errors.New("pase: MagicLinkTTL must be non-negative")
|
||||
} else if opts.MagicLinkTTL == 0 {
|
||||
opts.MagicLinkTTL = DefaultMagicLinkTTL
|
||||
} else if opts.MagicLinkTTL != 0 {
|
||||
magicLinkTTL = opts.MagicLinkTTL
|
||||
}
|
||||
|
||||
return &Service{
|
||||
store: s,
|
||||
idGenerator: opts.IDGenerator,
|
||||
operationTimeout: opts.OperationTimeout,
|
||||
magicLinkTTL: opts.MagicLinkTTL,
|
||||
idGenerator: idGenerator,
|
||||
operationTimeout: operationTimeout,
|
||||
magicLinkTTL: magicLinkTTL,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue