diff --git a/Makefile b/Makefile index dc2e692..c20a551 100644 --- a/Makefile +++ b/Makefile @@ -57,15 +57,18 @@ $(GO_META_LINTER): .PHONY: test test: - go test -v ./... + go test -vet -coverprofile=coverage.out -v ./... .PHONY: analyze analyze: install-deps @echo "Analyzing code..." - -gometalinter --disable=gotype --enable=gofmt --enable=goimports --enable=unused --deadline=2m --vendor ./... + gometalinter --enable=testify --enable=test --enable=gofmt --enable=goimports --enable=megacheck --enable=nakedret --enable=unparam --deadline=2m --vendor ./... imports: - goimports -w *.go + gometalinter --disable-all --enable=goimports --vendor ./... fmt: - gofmt -w -s *.go + gometalinter --disable-all --enable=gofmt --vendor ./... + +lint: + gometalinter --disable-all --enable=golint --vendor ./... diff --git a/cmd/root.go b/cmd/root.go index 418bec7..08e5f95 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -26,7 +26,7 @@ var RootCmd = &cobra.Command{ var httpPort int64 = 8000 var statsHost = "localhost" var statsPort int64 = 8125 -var stat statsd.Client +var statsClient statsd.Client func init() { RootCmd.Run = create @@ -54,14 +54,14 @@ func create(cmd *cobra.Command, args []string) { log.Infof("Statsd host : %s", statsHost) log.Infof("Statsd port : %d", statsPort) - stat, err := statsd.New(statsd.Address(fmt.Sprintf("%s:%d", statsHost, statsPort))) // Connect to the UDP host:port + statsClient, err := statsd.New(statsd.Address(fmt.Sprintf("%s:%d", statsHost, statsPort))) // Connect to the UDP host:port if err != nil { // If nothing is listening on the target port, an error is returned and // the returned client does nothing but is still usable. So we can // just log the error and go on. log.Print(err) } - defer stat.Close() + defer statsClient.Close() log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", httpPort), r)) @@ -73,7 +73,7 @@ var books []models.Book // Get All Books func getBooks(w http.ResponseWriter, r *http.Request) { // Increment our stats - stat.Increment("restapi.book.get.counter") + statsClient.Increment("restapi.book.get.counter") // Set the response type w.Header().Set("Content-Type", "application/json") @@ -86,7 +86,7 @@ func getBooks(w http.ResponseWriter, r *http.Request) { // Get Single Book func getBook(w http.ResponseWriter, r *http.Request) { // Increment our stats - stat.Increment("restapi.book.getId.counter") + statsClient.Increment("restapi.book.getId.counter") // Set the response type w.Header().Set("Content-Type", "application/json") @@ -114,7 +114,7 @@ func getBook(w http.ResponseWriter, r *http.Request) { // Create Books func createBook(w http.ResponseWriter, r *http.Request) { // Increment our stats - stat.Increment("restapi.book.create.counter") + statsClient.Increment("restapi.book.create.counter") // Set the response type w.Header().Set("Content-Type", "application/json") @@ -137,7 +137,7 @@ func createBook(w http.ResponseWriter, r *http.Request) { // Update Book func updateBook(w http.ResponseWriter, r *http.Request) { // Increment our stats - stat.Increment("restapi.book.update.counter") + statsClient.Increment("restapi.book.update.counter") // Set the response type w.Header().Set("Content-Type", "application/json") @@ -175,7 +175,7 @@ func updateBook(w http.ResponseWriter, r *http.Request) { // Delete Book func deleteBook(w http.ResponseWriter, r *http.Request) { // Increment our stats - stat.Increment("restapi.book.delete.counter") + statsClient.Increment("restapi.book.delete.counter") // Set the response type w.Header().Set("Content-Type", "application/json")