-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
106 lines (86 loc) · 2.51 KB
/
structs.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package state_machine
import (
"sync"
"github.com/joaosoft/logger"
)
type stateMap map[string]*state
type Context struct {
Role RoleType
StateMachine StateMachineType
From string
To string
Resource interface{}
Args []interface{}
}
type ManualHandler func(ctx *Context) error
type LoadHandler func(ctx *Context) error
type CheckHandler func(ctx *Context) (bool, error)
type ExecuteHandler func(ctx *Context) error
type EventSuccessHandler func(ctx *Context) error
type EventErrorHandler func(ctx *Context, err error) error
type TransitionHandler func(ctx *Context) error
type manualHandlerMap map[manualHandlerKey]manualHandlerList
type manualHandlerList []ManualHandler
type loadHandlerMap map[string]LoadHandler
type checkHandlerMap map[string]CheckHandler
type executeHandlerMap map[string]ExecuteHandler
type eventSuccessHandlerMap map[string]EventSuccessHandler
type eventErrorHandlerMap map[string]EventErrorHandler
type stateMachineHandlersMap map[StateMachineType]*handlersMap
type handlers struct {
handlersMap *handlersMap
stateMachineHandlersMap stateMachineHandlersMap
}
type stateMachine struct {
config *stateMachineConfig
stateMachineMap stateMachineMap
roleStateMachineMap roleStateMachineMap
handlers *handlers
logger logger.ILogger
mux *sync.RWMutex
}
type stateMachineMap map[StateMachineType]*stateMachineData
type stateMachineData struct {
stateMap stateMap
transitionHandler TransitionHandler
}
type roleStateMachineMap map[RoleType]stateMachineMap
type state struct {
id string
name string
transitionMap transitionMap
}
type transitionMap map[string]*Transition
type Transition struct {
Id string `json:"id"`
Name string `json:"name"`
handler handler
}
type handler struct {
load loadHandlerList
check checkHandlerList
execute executeHandlerList
events events
}
type events struct {
success eventSuccessHandlerList
error eventErrorHandlerList
}
type loadHandlerList []LoadHandler
type checkHandlerList []CheckHandler
type executeHandlerList []ExecuteHandler
type eventSuccessHandlerList []EventSuccessHandler
type eventErrorHandlerList []EventErrorHandler
type handlersMap struct {
manual manualHandlerMap
Load loadHandlerMap
check checkHandlerMap
execute executeHandlerMap
events *eventMap
}
type eventMap struct {
success eventSuccessHandlerMap
error eventErrorHandlerMap
}
type RoleType string
type StateMachineType string