EventType is now based on string

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-08-10 17:04:40 -03:00
parent 79181b2a17
commit ce8ec8a151
5 changed files with 14 additions and 34 deletions

View File

@@ -1,40 +1,20 @@
package event package event
var events []string type EventType string
type EventType int
func (e EventType) String() string { func (e EventType) String() string {
return events[int(e)] return string(e)
}
func ciota(s string) EventType {
events = append(events, s)
return EventType(len(events) - 1)
}
func FindEventType(name string) (EventType, bool) {
for i, event := range events {
if event == name {
return EventType(i), true
}
}
return EventType(-1), false
}
func NewEventType(name string) EventType {
return ciota(name)
} }
var ( var (
INSTANCE_VIEWPORT_RESIZE = ciota("instance viewport resize") INSTANCE_VIEWPORT_RESIZE = EventType("instance viewport resize")
INSTANCE_DELETE = ciota("instance delete") INSTANCE_DELETE = EventType("instance delete")
INSTANCE_NEW = ciota("instance new") INSTANCE_NEW = EventType("instance new")
INSTANCE_STATS = ciota("instance stats") INSTANCE_STATS = EventType("instance stats")
SESSION_NEW = ciota("session new") SESSION_NEW = EventType("session new")
SESSION_END = ciota("session end") SESSION_END = EventType("session end")
SESSION_READY = ciota("session ready") SESSION_READY = EventType("session ready")
SESSION_BUILDER_OUT = ciota("session builder out") SESSION_BUILDER_OUT = EventType("session builder out")
) )
type Handler func(sessionId string, args ...interface{}) type Handler func(sessionId string, args ...interface{})

View File

@@ -22,7 +22,7 @@ type checkPorts struct {
var CheckPortsEvent event.EventType var CheckPortsEvent event.EventType
func init() { func init() {
CheckPortsEvent = event.NewEventType("instance docker ports") CheckPortsEvent = event.EventType("instance docker ports")
} }
func (t *checkPorts) Name() string { func (t *checkPorts) Name() string {

View File

@@ -24,7 +24,7 @@ type checkSwarmPorts struct {
var CheckSwarmPortsEvent event.EventType var CheckSwarmPortsEvent event.EventType
func init() { func init() {
CheckSwarmPortsEvent = event.NewEventType("instance docker swarm ports") CheckSwarmPortsEvent = event.EventType("instance docker swarm ports")
} }
func (t *checkSwarmPorts) Name() string { func (t *checkSwarmPorts) Name() string {

View File

@@ -24,7 +24,7 @@ type checkSwarmStatus struct {
var CheckSwarmStatusEvent event.EventType var CheckSwarmStatusEvent event.EventType
func init() { func init() {
CheckSwarmStatusEvent = event.NewEventType("instance docker swarm status") CheckSwarmStatusEvent = event.EventType("instance docker swarm status")
} }
func (t *checkSwarmStatus) Name() string { func (t *checkSwarmStatus) Name() string {

View File

@@ -27,7 +27,7 @@ type collectStats struct {
var CollectStatsEvent event.EventType var CollectStatsEvent event.EventType
func init() { func init() {
CollectStatsEvent = event.NewEventType("instance stats") CollectStatsEvent = event.EventType("instance stats")
} }
func (t *collectStats) Name() string { func (t *collectStats) Name() string {