diff --git a/.linter.conf b/.linter.conf new file mode 100644 index 0000000..223c4ae --- /dev/null +++ b/.linter.conf @@ -0,0 +1,4 @@ +{ + "DisableAll": true, + "Enable": ["golint", "vet", "errcheck"] +} diff --git a/Makefile b/Makefile index cc93278..766ec29 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,8 @@ deps: dev-deps dev-deps: go get github.com/smartystreets/goconvey/convey - go get github.com/golang/lint/golint + go get github.com/alecthomas/gometalinter + gometalinter --install cover: go test -v ./... --cover @@ -21,5 +22,5 @@ build: go build -v ./... lint: - golint ./... - go vet ./... + gometalinter --config .linter.conf + diff --git a/main.go b/main.go index 6fc6c35..cad7674 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ package main import ( "fmt" + "log" "net/http" "github.com/nats-io/nats" @@ -17,6 +18,7 @@ var s *sse.Server var host string var port string var secret string +var err error func main() { setup() @@ -33,20 +35,64 @@ func main() { mux.HandleFunc("/events", authMiddleware) // Start nats handler, subscribe to all events related with the monitor - n.Subscribe("monitor.user", natsHandler) - n.Subscribe("service.create", natsHandler) - n.Subscribe("service.delete", natsHandler) - n.Subscribe("service.create.done", natsHandler) - n.Subscribe("service.create.error", natsHandler) - n.Subscribe("service.delete.done", natsHandler) - n.Subscribe("service.delete.error", natsHandler) - n.Subscribe("service.import.done", natsHandler) - n.Subscribe("service.import.error", natsHandler) - - n.Subscribe("*.*", genericHandler) - n.Subscribe("*.*.*", genericHandler) + _, err = n.Subscribe("monitor.user", natsHandler) + if err != nil { + log.Println(err) + return + } + _, err = n.Subscribe("service.create", natsHandler) + if err != nil { + log.Println(err) + return + } + _, err = n.Subscribe("service.delete", natsHandler) + if err != nil { + log.Println(err) + return + } + _, err = n.Subscribe("service.create.done", natsHandler) + if err != nil { + log.Println(err) + return + } + _, err = n.Subscribe("service.create.error", natsHandler) + if err != nil { + log.Println(err) + return + } + _, err = n.Subscribe("service.delete.done", natsHandler) + if err != nil { + log.Println(err) + return + } + _, err = n.Subscribe("service.delete.error", natsHandler) + if err != nil { + log.Println(err) + return + } + _, err = n.Subscribe("service.import.done", natsHandler) + if err != nil { + log.Println(err) + return + } + _, err = n.Subscribe("service.import.error", natsHandler) + if err != nil { + log.Println(err) + return + } + + _, err = n.Subscribe("*.*", genericHandler) + if err != nil { + log.Println(err) + return + } + _, err = n.Subscribe("*.*.*", genericHandler) + if err != nil { + log.Println(err) + return + } // Start Listening addr := fmt.Sprintf("%s:%s", host, port) - http.ListenAndServe(addr, mux) + _ = http.ListenAndServe(addr, mux) } diff --git a/main_test.go b/main_test.go index 46b467c..5bc0d53 100644 --- a/main_test.go +++ b/main_test.go @@ -99,7 +99,9 @@ func TestMain(t *testing.T) { s.CreateStream("test") time.Sleep(time.Millisecond * 10) - go cl.SubscribeChan("test", rcv) + go func() { + _ = cl.SubscribeChan("test", rcv) + }() time.Sleep(time.Millisecond * 10) Convey("It should publish a message to the stream", func() { @@ -120,7 +122,9 @@ func TestMain(t *testing.T) { time.Sleep(time.Millisecond * 10) - go cl.SubscribeChan("test", rcv) + go func() { + _ = cl.SubscribeChan("test", rcv) + }() time.Sleep(time.Millisecond * 10) Convey("It should not publish a message to the stream", func() { diff --git a/setup.go b/setup.go index f43dac2..d9bef62 100644 --- a/setup.go +++ b/setup.go @@ -42,7 +42,9 @@ func setup() { if err != nil { panic("Can't get monitor config") } - json.Unmarshal(msg.Data, &cfg) + if err := json.Unmarshal(msg.Data, &cfg); err != nil { + panic("Can't process monitor config") + } host = cfg.Host port = cfg.Port