Skip to content

Commit

Permalink
Standarize messages
Browse files Browse the repository at this point in the history
  • Loading branch information
adriacidre committed Oct 10, 2016
1 parent c3d2046 commit 8ed7c31
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
1 change: 1 addition & 0 deletions c_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (n *Firewall) Handle(subject string, components []interface{}, lines []Mess
case "firewalls.delete":
return append(lines, Message{Body: "Deleting firewalls:", Level: "INFO"})
case "firewalls.delete.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "Firewalls deleted", Level: "INFO"})
case "firewalls.delete.error":
lines = n.getDetails(components)
Expand Down
1 change: 1 addition & 0 deletions c_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (n *Instance) Handle(subject string, components []interface{}, lines []Mess
case "instances.delete":
return append(lines, Message{Body: "Deleting instances", Level: "INFO"})
case "instances.delete.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "Instances deleted", Level: "INFO"})
case "instances.delete.error":
lines = n.getDetails(components)
Expand Down
1 change: 1 addition & 0 deletions c_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (n *Nat) Handle(subject string, components []interface{}, lines []Message)
case "nats.delete":
return append(lines, Message{Body: "Deleting nats:", Level: "INFO"})
case "nats.delete.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "Nats deleted", Level: "INFO"})
case "nats.delete.error":
lines = n.getDetails(components)
Expand Down
27 changes: 8 additions & 19 deletions c_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,20 @@ type Network struct {
func (n *Network) Handle(subject string, components []interface{}, lines []Message) []Message {
switch subject {
case "networks.create":
lines = n.listCreate(components)
return append(lines, Message{Body: "Creating networks:", Level: "INFO"})
case "networks.create.done":
lines = n.listCreateDone(components)
lines = n.getDetails(components)
return append(lines, Message{Body: "Networks successfully created", Level: "INFO"})
case "networks.delete":
lines = n.listDelete(components)
return append(lines, Message{Body: "Deleting networks:", Level: "INFO"})
case "networks.delete.done":
lines = n.listDeleteDone(components)
lines = n.getDetails(components)
return append(lines, Message{Body: "Networks deleted", Level: "INFO"})
}
return lines
}

func (n *Network) listCreate(components []interface{}) (lines []Message) {
return append(lines, Message{Body: "Creating networks:", Level: "INFO"})
}

func (n *Network) listDelete(components []interface{}) (lines []Message) {
return append(lines, Message{Body: "Networks deleted", Level: "INFO"})
}

func (n *Network) listCreateDone(components []interface{}) (lines []Message) {
func (n *Network) getDetails(components []interface{}) (lines []Message) {
for _, v := range components {
r := v.(map[string]interface{})
ip := r["range"].(string)
Expand All @@ -47,10 +41,5 @@ func (n *Network) listCreateDone(components []interface{}) (lines []Message) {
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}
}

return append(lines, Message{Body: "Networks successfully created", Level: "INFO"})
}

func (n *Network) listDeleteDone(components []interface{}) (lines []Message) {
return append(lines, Message{Body: "Deleting networks:", Level: "INFO"})
return lines
}

0 comments on commit 8ed7c31

Please sign in to comment.