Merge pull request #2372 from HotelsDotCom/flexible-lock-sessions

More flexible Session configuration when using api.Lock
This commit is contained in:
James Phillips 2016-10-05 17:52:12 -07:00 committed by GitHub
commit 25455c97c3
1 changed files with 7 additions and 3 deletions

View File

@ -72,6 +72,7 @@ type LockOptions struct {
Key string // Must be set and have write permissions Key string // Must be set and have write permissions
Value []byte // Optional, value to associate with the lock Value []byte // Optional, value to associate with the lock
Session string // Optional, created if not specified Session string // Optional, created if not specified
SessionOpts *SessionEntry // Optional, options to use when creating a session
SessionName string // Optional, defaults to DefaultLockSessionName SessionName string // Optional, defaults to DefaultLockSessionName
SessionTTL string // Optional, defaults to DefaultLockSessionTTL SessionTTL string // Optional, defaults to DefaultLockSessionTTL
MonitorRetries int // Optional, defaults to 0 which means no retries MonitorRetries int // Optional, defaults to 0 which means no retries
@ -329,10 +330,13 @@ func (l *Lock) Destroy() error {
// createSession is used to create a new managed session // createSession is used to create a new managed session
func (l *Lock) createSession() (string, error) { func (l *Lock) createSession() (string, error) {
session := l.c.Session() session := l.c.Session()
se := &SessionEntry{ se := l.opts.SessionOpts
if se == nil {
se = &SessionEntry{
Name: l.opts.SessionName, Name: l.opts.SessionName,
TTL: l.opts.SessionTTL, TTL: l.opts.SessionTTL,
} }
}
id, _, err := session.Create(se, nil) id, _, err := session.Create(se, nil)
if err != nil { if err != nil {
return "", err return "", err