Skip to content

Commit

Permalink
Merge pull request #2372 from HotelsDotCom/flexible-lock-sessions
Browse files Browse the repository at this point in the history
More flexible Session configuration when using api.Lock
  • Loading branch information
slackpad authored Oct 6, 2016
2 parents 9fc0c0e + 2ed58a2 commit 25455c9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions api/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type LockOptions struct {
Key string // Must be set and have write permissions
Value []byte // Optional, value to associate with the lock
Session string // Optional, created if not specified
SessionOpts *SessionEntry // Optional, options to use when creating a session
SessionName string // Optional, defaults to DefaultLockSessionName
SessionTTL string // Optional, defaults to DefaultLockSessionTTL
MonitorRetries int // Optional, defaults to 0 which means no retries
Expand Down Expand Up @@ -329,9 +330,12 @@ func (l *Lock) Destroy() error {
// createSession is used to create a new managed session
func (l *Lock) createSession() (string, error) {
session := l.c.Session()
se := &SessionEntry{
Name: l.opts.SessionName,
TTL: l.opts.SessionTTL,
se := l.opts.SessionOpts
if se == nil {
se = &SessionEntry{
Name: l.opts.SessionName,
TTL: l.opts.SessionTTL,
}
}
id, _, err := session.Create(se, nil)
if err != nil {
Expand Down

0 comments on commit 25455c9

Please sign in to comment.