Skip to content

Commit

Permalink
EventType is now based on string
Browse files Browse the repository at this point in the history
  • Loading branch information
xetorthio committed Aug 10, 2017
1 parent 79181b2 commit ce8ec8a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 34 deletions.
40 changes: 10 additions & 30 deletions event/event.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
package event

var events []string

type EventType int
type EventType string

func (e EventType) String() string {
return events[int(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)
return string(e)
}

var (
INSTANCE_VIEWPORT_RESIZE = ciota("instance viewport resize")
INSTANCE_DELETE = ciota("instance delete")
INSTANCE_NEW = ciota("instance new")
INSTANCE_STATS = ciota("instance stats")
SESSION_NEW = ciota("session new")
SESSION_END = ciota("session end")
SESSION_READY = ciota("session ready")
SESSION_BUILDER_OUT = ciota("session builder out")
INSTANCE_VIEWPORT_RESIZE = EventType("instance viewport resize")
INSTANCE_DELETE = EventType("instance delete")
INSTANCE_NEW = EventType("instance new")
INSTANCE_STATS = EventType("instance stats")
SESSION_NEW = EventType("session new")
SESSION_END = EventType("session end")
SESSION_READY = EventType("session ready")
SESSION_BUILDER_OUT = EventType("session builder out")
)

type Handler func(sessionId string, args ...interface{})
Expand Down
2 changes: 1 addition & 1 deletion scheduler/task/check_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type checkPorts struct {
var CheckPortsEvent event.EventType

func init() {
CheckPortsEvent = event.NewEventType("instance docker ports")
CheckPortsEvent = event.EventType("instance docker ports")
}

func (t *checkPorts) Name() string {
Expand Down
2 changes: 1 addition & 1 deletion scheduler/task/check_swarm_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type checkSwarmPorts struct {
var CheckSwarmPortsEvent event.EventType

func init() {
CheckSwarmPortsEvent = event.NewEventType("instance docker swarm ports")
CheckSwarmPortsEvent = event.EventType("instance docker swarm ports")
}

func (t *checkSwarmPorts) Name() string {
Expand Down
2 changes: 1 addition & 1 deletion scheduler/task/check_swarm_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type checkSwarmStatus struct {
var CheckSwarmStatusEvent event.EventType

func init() {
CheckSwarmStatusEvent = event.NewEventType("instance docker swarm status")
CheckSwarmStatusEvent = event.EventType("instance docker swarm status")
}

func (t *checkSwarmStatus) Name() string {
Expand Down
2 changes: 1 addition & 1 deletion scheduler/task/collect_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type collectStats struct {
var CollectStatsEvent event.EventType

func init() {
CollectStatsEvent = event.NewEventType("instance stats")
CollectStatsEvent = event.EventType("instance stats")
}

func (t *collectStats) Name() string {
Expand Down

0 comments on commit ce8ec8a

Please sign in to comment.