41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package proxy
|
|
|
|
type State string
|
|
|
|
const (
|
|
StateFetched State = "FETCHED"
|
|
StateChecking State = "CHECKING"
|
|
StateAvailable State = "AVAILABLE"
|
|
StateSuspect State = "SUSPECT"
|
|
StateDraining State = "DRAINING"
|
|
StateUnhealthy State = "UNHEALTHY"
|
|
StateExtracted State = "EXTRACTED"
|
|
StateExpired State = "EXPIRED"
|
|
StateRemoved State = "REMOVED"
|
|
)
|
|
|
|
var transitions = map[State]map[State]struct{}{
|
|
StateFetched: set(StateChecking, StateExpired, StateRemoved),
|
|
StateChecking: set(StateAvailable, StateUnhealthy, StateExpired, StateRemoved),
|
|
StateAvailable: set(StateSuspect, StateDraining, StateExtracted, StateExpired),
|
|
StateSuspect: set(StateAvailable, StateUnhealthy, StateDraining, StateExpired),
|
|
StateDraining: set(StateExpired, StateUnhealthy, StateRemoved),
|
|
StateUnhealthy: set(StateChecking, StateRemoved, StateExpired),
|
|
StateExtracted: set(StateExpired, StateRemoved),
|
|
StateExpired: set(StateRemoved),
|
|
StateRemoved: {},
|
|
}
|
|
|
|
func CanTransition(current, next State) bool {
|
|
_, ok := transitions[current][next]
|
|
return ok
|
|
}
|
|
|
|
func set(states ...State) map[State]struct{} {
|
|
result := make(map[State]struct{}, len(states))
|
|
for _, state := range states {
|
|
result[state] = struct{}{}
|
|
}
|
|
return result
|
|
}
|