2019-05-06 14:33:04 +01:00
|
|
|
package sessions
|
|
|
|
|
|
|
|
import (
|
2021-06-02 20:08:19 +02:00
|
|
|
"context"
|
|
|
|
"errors"
|
2019-05-06 14:33:04 +01:00
|
|
|
"net/http"
|
2021-06-02 20:08:19 +02:00
|
|
|
"time"
|
2019-05-06 14:33:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// SessionStore is an interface to storing user sessions in the proxy
|
|
|
|
type SessionStore interface {
|
2019-05-08 16:36:28 +01:00
|
|
|
Save(rw http.ResponseWriter, req *http.Request, s *SessionState) error
|
|
|
|
Load(req *http.Request) (*SessionState, error)
|
|
|
|
Clear(rw http.ResponseWriter, req *http.Request) error
|
2022-12-23 11:08:12 +02:00
|
|
|
VerifyConnection(ctx context.Context) error
|
2019-05-06 14:33:04 +01:00
|
|
|
}
|
2021-06-02 20:08:19 +02:00
|
|
|
|
|
|
|
var ErrLockNotObtained = errors.New("lock: not obtained")
|
|
|
|
var ErrNotLocked = errors.New("tried to release not existing lock")
|
|
|
|
|
|
|
|
// Lock is an interface for controlling session locks
|
|
|
|
type Lock interface {
|
|
|
|
// Obtain obtains the lock on the distributed
|
|
|
|
// lock resource if no lock exists yet.
|
|
|
|
// Otherwise it will return ErrLockNotObtained
|
|
|
|
Obtain(ctx context.Context, expiration time.Duration) error
|
|
|
|
// Peek returns true if the lock currently exists
|
|
|
|
// Otherwise it returns false.
|
|
|
|
Peek(ctx context.Context) (bool, error)
|
|
|
|
// Refresh refreshes the expiration time of the lock,
|
|
|
|
// if is still applied.
|
|
|
|
// Otherwise it will return ErrNotLocked
|
|
|
|
Refresh(ctx context.Context, expiration time.Duration) error
|
|
|
|
// Release removes the existing lock,
|
|
|
|
// Otherwise it will return ErrNotLocked
|
|
|
|
Release(ctx context.Context) error
|
|
|
|
}
|