Skip to content

Commit

Permalink
Clean up error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
g3kk0 committed Jul 10, 2017
1 parent cb9c784 commit 0dbb594
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
9 changes: 6 additions & 3 deletions component.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"encoding/json"
"log"
"strings"

"github.com/nats-io/nats"
Expand All @@ -29,17 +30,19 @@ func processComponent(msg *nats.Msg) {
c.Subject = msg.Subject

if err := json.Unmarshal(msg.Data, &c); err != nil {
panic(err)
log.Println(err)
return
}

id := c.getID()

data, err := json.Marshal(c)
if err != nil {
panic(err)
log.Println(err)
return
}

publishEvent(id, data)
ss.Publish(id, data)
}

func (c *Component) getID() string {
Expand Down
9 changes: 0 additions & 9 deletions event.go

This file was deleted.

12 changes: 6 additions & 6 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ func processService(msg *nats.Msg) {
s.Subject = msg.Subject

if err := json.Unmarshal(msg.Data, &s); err != nil {
panic(err)
log.Println(err)
return
}

id := s.getID()

data, err := json.Marshal(s)
if err != nil {
panic(err)
log.Println(err)
return
}

switch msg.Subject {
case "service.create", "service.delete":
// Create new stream
log.Println("Creating stream: ", id)
ss.CreateStream(id)
publishEvent(id, data)
ss.Publish(id, data)
case "service.create.done", "service.create.error", "service.delete.done", "service.delete.error", "service.import.done", "service.import.error":
publishEvent(id, data)
// publishEvent(id, cliHangup)

ss.Publish(id, data)
time.Sleep(10 * time.Millisecond)
// Remove stream when the build completes
log.Println("Closing stream: ", id)
Expand Down

0 comments on commit 0dbb594

Please sign in to comment.