-
Notifications
You must be signed in to change notification settings - Fork 1
/
session.go
73 lines (55 loc) · 1.58 KB
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package saga
type State int
const (
StateCommon State = iota
StateCompleted
StateFailed
StateIsCompensating
StateIsRetrying
)
type SessionFactory[S Session] func(map[string]interface{}) S
//type SessionID string
type Session interface {
// ID returns the ID of the session.
ID() string
// CurrentStep returns the current step of the session.
CurrentStep() Step
// UpdateCurrentStep updates the current step of the session.
UpdateCurrentStep(step Step) error
// IsPending returns true if the session is pending. Session can be pending state when following conditions are met:
//
// - The session is in.
//
// - The session is in.
//
// - The session is in.
IsPending() bool
// SetPending sets the pending state of the session.
SetPending(pending bool)
// State returns the current state of the session.
State() State
// SetState sets the state of the session.
SetState(state State)
}
type SessionRepository[S Session, Tx TxContext] interface {
// Load finds a session by its ID.
Load(id string) (S, error)
// Save saves a session.
Save(sess S) Executable[Tx]
// Delete deletes a session.
Delete(sess S) Executable[Tx]
}
type sessionRepository[Tx TxContext] struct {
load func(id string) (Session, error)
save func(sess Session) Executable[Tx]
delete func(sess Session) Executable[Tx]
}
func (s *sessionRepository[Tx]) Load(id string) (Session, error) {
return s.load(id)
}
func (s *sessionRepository[Tx]) Save(sess Session) Executable[Tx] {
return s.save(sess)
}
func (s *sessionRepository[Tx]) Delete(sess Session) Executable[Tx] {
return s.delete(sess)
}