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")
|
return nil, errors.New("pase: store is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.IDGenerator == nil {
|
idGenerator := DefaultIDGenerator()
|
||||||
opts.IDGenerator = DefaultIDGenerator()
|
if opts.IDGenerator != nil {
|
||||||
|
idGenerator = opts.IDGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operationTimeout := DefaultOperationTimeout
|
||||||
if opts.OperationTimeout < 0 {
|
if opts.OperationTimeout < 0 {
|
||||||
return nil, errors.New("pase: OperationTimeout must be non-negative")
|
return nil, errors.New("pase: OperationTimeout must be non-negative")
|
||||||
} else if opts.OperationTimeout == 0 {
|
} else if opts.OperationTimeout != 0 {
|
||||||
opts.OperationTimeout = DefaultOperationTimeout
|
operationTimeout = opts.OperationTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
magicLinkTTL := DefaultMagicLinkTTL
|
||||||
if opts.MagicLinkTTL < 0 {
|
if opts.MagicLinkTTL < 0 {
|
||||||
return nil, errors.New("pase: MagicLinkTTL must be non-negative")
|
return nil, errors.New("pase: MagicLinkTTL must be non-negative")
|
||||||
} else if opts.MagicLinkTTL == 0 {
|
} else if opts.MagicLinkTTL != 0 {
|
||||||
opts.MagicLinkTTL = DefaultMagicLinkTTL
|
magicLinkTTL = opts.MagicLinkTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Service{
|
return &Service{
|
||||||
store: s,
|
store: s,
|
||||||
idGenerator: opts.IDGenerator,
|
idGenerator: idGenerator,
|
||||||
operationTimeout: opts.OperationTimeout,
|
operationTimeout: operationTimeout,
|
||||||
magicLinkTTL: opts.MagicLinkTTL,
|
magicLinkTTL: magicLinkTTL,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue