Skip to content

Commit

Permalink
Use gometalinter for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
adriacidre committed Mar 2, 2017
1 parent 8f3e914 commit e0c4bde
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .linter.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"DisableAll": true,
"Enable": ["golint", "vet", "errcheck"]
}
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,5 +22,5 @@ build:
go build -v ./...

lint:
golint ./...
go vet ./...
gometalinter --config .linter.conf

72 changes: 59 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"fmt"
"log"
"net/http"

"github.com/nats-io/nats"
Expand All @@ -17,6 +18,7 @@ var s *sse.Server
var host string
var port string
var secret string
var err error

func main() {
setup()
Expand All @@ -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)
}
8 changes: 6 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e0c4bde

Please sign in to comment.