From 0215b2c7d6f0c4910202a752f47b3e570193c426 Mon Sep 17 00:00:00 2001 From: Peter Edge Date: Fri, 1 Feb 2019 11:22:59 -0500 Subject: [PATCH] Add Makefile for development (#67) * Add Makefile for development * Update README.md * Remove reference to cover --- .circleci/config.yml | 2 +- .gitignore | 7 +- Makefile | 126 ++++++++++++++++++++++++++ README.md | 13 +++ go.mod | 9 ++ go.sum | 26 ++++++ internal/helloworld/greeter_server.go | 6 +- internal/tools/tools.go | 10 ++ 8 files changed, 193 insertions(+), 6 deletions(-) create mode 100644 Makefile create mode 100644 internal/tools/tools.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 90fd6c89..1c5557c6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ jobs: - image: circleci/golang:1.11 steps: - checkout - - run: go test ./... + - run: make workflows: version: 2 github_test: diff --git a/.gitignore b/.gitignore index 059ac213..3b36470d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,10 @@ *.out -cmd/ghz/ghz -cmd/ghz-web/ghz-web -cmd/server/server +/cmd/ghz/ghz +/cmd/ghz-web/ghz-web +/cmd/server/server +/.tmp/ dist build diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..b522a64b --- /dev/null +++ b/Makefile @@ -0,0 +1,126 @@ +# SHELL defines the shell that the Makefile uses. +# We also set -o pipefail so that if a previous command in a pipeline fails, a command fails. +# http://redsymbol.net/articles/unofficial-bash-strict-mode +SHELL := /bin/bash -o pipefail + +############### RUNTIME VARIABLES ############### +# The following variables can be set by the user +# To adjust the functionality of the targets. +################################################# + +# Set V=1 on the command line to turn off all suppression. Many trivial +# commands are suppressed with "@", by setting V=1, this will be turned off. +ifeq ($(V),1) + AT := +else + AT := @ +endif + +# GO_PKGS is the list of packages to run our linting and testing commands against. +# This can be set when invoking a target. +GO_PKGS ?= $(shell go list ./...) + +# GO_TEST_FLAGS are the flags passed to go test +GO_TEST_FLAGS ?= -race + +# Set OPEN_COVERAGE=1 to open the coverage.html file after running make cover. +ifeq ($(OPEN_COVERAGE),1) + OPEN_COVERAGE_HTML := 1 +else + OPEN_COVERAGE_HTML := +endif + +################################################# +##### Everything below should not be edited ##### +################################################# + +# UNAME_OS stores the value of uname -s. +UNAME_OS := $(shell uname -s) +# UNAME_ARCH stores the value of uname -m. +UNAME_ARCH := $(shell uname -m) + +# TMP_BASE is the base directory used for TMP. +# Use TMP and not TMP_BASE as the temporary directory. +TMP_BASE := .tmp +# TMP is the temporary directory used. +# This is based on UNAME_OS and UNAME_ARCH to make sure there are no issues +# switching between platform builds. +TMP := $(TMP_BASE)/$(UNAME_OS)/$(UNAME_ARCH) +# TMP_BIN is where we install binaries for usage during development. +TMP_BIN = $(TMP)/bin +# TMP_COVERAGE is where we store code coverage files. +TMP_COVERAGE := $(TMP_BASE)/coverage + +# The following unexports and exports put us into Golang Modules mode. + +# Make sure GOPATH is unset so that it is not possible to interfere with other packages. +unexport GOPATH +# Make sure GOROOT is unset so that there are no issues. +unexport GOROOT +# Turn Golang modules on +export GO111MODULE := on +# Set the location where we install Golang binaries via go install to TMP_BIN. +export GOBIN := $(abspath $(TMP_BIN)) +# Add GOBIN to to the front of the PATH. This allows us to invoke binaries we install. +export PATH := :$(GOBIN):$(PATH) + +# GO_MODULE extracts the module name from the go.mod file. +GO_MODULE := $(shell grep '^module ' go.mod | cut -f 2 -d ' ') + +# Run all by default when "make" is invoked. +.DEFAULT_GOAL := all + +# All runs the default lint, test, and code coverage targets. +.PHONY: all +all: lint cover + +# Clean removes all temporary files. +.PHONY: clean +clean: + rm -rf $(TMP_BASE) + +# Golint runs the golint linter. +.PHONY: golint +golint: + $(AT) go install github.com/golang/lint/golint + golint -set_exit_status $(GO_PKGS) + +# Errcheck runs the errcheck linter. +.PHONY: errcheck +errcheck: + $(AT) go install github.com/kisielk/errcheck + errcheck -ignoretests $(GO_PKGS) + +# Staticcheck runs the staticcheck linter. +.PHONY: staticcheck +staticcheck: + $(AT) go install honnef.co/go/tools/cmd/staticcheck + staticcheck --tests=false $(GO_PKGS) + +# Lint runs all linters. This is the main lint target to run. +# TODO: add errcheck and staticcheck when the code is updated to pass them +.PHONY: lint +lint: golint + +# Test runs go test on GO_PKGS. This does not produce code coverage. +.PHONY: test +test: + go test $(GO_TEST_FLAGS) $(GO_PKGS) + +# Cover runs go_test on GO_PKGS and produces code coverage in multiple formats. +# A coverage.html file for human viewing will be at $(TMP_COVERAGE)/coverage.html +# This target will echo "open $(TMP_COVERAGE)/coverage.html" with TMP_COVERAGE +# expanded so that you can easily copy "open $(TMP_COVERAGE)/coverage.html" into +# your terminal as a command to run, and then see the code coverage output locally. +.PHONY: cover +cover: + $(AT) rm -rf $(TMP_COVERAGE) + $(AT) mkdir -p $(TMP_COVERAGE) + go test $(GO_TEST_FLAGS) -coverprofile=$(TMP_COVERAGE)/coverage.txt -coverpkg=$(shell echo $(GO_PKGS) | grep -v \/cmd\/ | tr ' ' ',') $(GO_PKGS) + $(AT) go tool cover -html=$(TMP_COVERAGE)/coverage.txt -o $(TMP_COVERAGE)/coverage.html + $(AT) echo + $(AT) go tool cover -func=$(TMP_COVERAGE)/coverage.txt | grep total + $(AT) echo + $(AT) echo Open the coverage report: + $(AT) echo open $(TMP_COVERAGE)/coverage.html + $(AT) if [ "$(OPEN_COVERAGE_HTML)" == "1" ]; then open $(TMP_COVERAGE)/coverage.html; fi diff --git a/README.md b/README.md index 302a9f53..350e085c 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,19 @@ printer := printer.ReportPrinter{ printer.Print("pretty") ``` +## Development + +Golang 1.11+ is required. + +``` +make # run all linters, tests, and produce code coverage +make lint # run all linters +make test # run tests +make cover # run tests and produce code coverage + +V=1 make # more verbosity +OPEN_COVERAGE=1 make cover # open code coverage.html after running +``` ## Credit diff --git a/go.mod b/go.mod index 2e8feb71..d91edbcd 100644 --- a/go.mod +++ b/go.mod @@ -4,16 +4,23 @@ require ( github.com/BurntSushi/toml v0.3.1 // indirect github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc github.com/bojand/hri v1.1.0 + github.com/denisenkom/go-mssqldb v0.0.0-20190121005146-b04fd42d9952 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect + github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 // indirect github.com/go-playground/locales v0.12.1 // indirect github.com/go-playground/universal-translator v0.16.0 // indirect github.com/go-playground/validator v9.25.0+incompatible github.com/go-sql-driver/mysql v1.4.1 // indirect + github.com/gofrs/uuid v3.2.0+incompatible // indirect + github.com/golang/lint v0.0.0-20181217174547-8f45f776aaf1 github.com/golang/protobuf v1.2.0 + github.com/google/go-cmp v0.2.0 // indirect github.com/jhump/protoreflect v1.1.0 github.com/jinzhu/configor v0.0.0-20180614024415-4edaf76fe188 github.com/jinzhu/gorm v1.9.2 github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a // indirect + github.com/jinzhu/now v0.0.0-20181116074157-8ec929ed50c3 // indirect + github.com/kisielk/errcheck v1.2.0 github.com/labstack/echo v3.3.5+incompatible github.com/labstack/gommon v0.2.8 github.com/leodido/go-urn v1.1.0 // indirect @@ -29,5 +36,7 @@ require ( golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc // indirect golang.org/x/net v0.0.0-20190110200230-915654e7eabc google.golang.org/grpc v1.17.0 + gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/yaml.v2 v2.2.2 // indirect + honnef.co/go/tools v0.0.0-20190128043916-71123fcbb8fe ) diff --git a/go.sum b/go.sum index e905270d..500aff49 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -8,8 +9,12 @@ github.com/bojand/hri v1.1.0/go.mod h1:qwGosuHpNn1S0nyw/mExN0+WZrDf4bQyWjhWh51y3 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/denisenkom/go-mssqldb v0.0.0-20190121005146-b04fd42d9952 h1:b5OnbZD49x9g+/FcYbs/vukEt8C/jUbGhCJ3uduQmu8= +github.com/denisenkom/go-mssqldb v0.0.0-20190121005146-b04fd42d9952/go.mod h1:xN/JuLBIz4bjkxNmByTiV1IbhfnYb6oo99phBn4Eqhc= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= +github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= github.com/go-playground/locales v0.12.1 h1:2FITxuFt/xuCNP1Acdhv62OzaCiviiE4kotfhkmOqEc= github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM= @@ -18,11 +23,18 @@ github.com/go-playground/validator v9.25.0+incompatible h1:yRnzUYNX6zfnss52l6tMc github.com/go-playground/validator v9.25.0+incompatible/go.mod h1:yrEkQXlcI+PugkyDjY2bRrL/UBU4f3rvrgkN3V8JEig= github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= +github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/lint v0.0.0-20181217174547-8f45f776aaf1 h1:6DVPu65tee05kY0/rciBQ47ue+AnuY8KTayV6VHikIo= +github.com/golang/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/jhump/protoreflect v1.1.0 h1:h+zsMrsiq0vIl7yWmeowmd8e8VtnWk75U04GgXA2s6Y= github.com/jhump/protoreflect v1.1.0/go.mod h1:kG/zRVeS2M91gYaCvvUbPkMjjtFQS4qqjcPFzFkh2zE= github.com/jinzhu/configor v0.0.0-20180614024415-4edaf76fe188 h1:XFhKsrhg0SBbAGFKWbwK81YkfbNyO2QItYQ05jqbpAU= @@ -31,6 +43,10 @@ github.com/jinzhu/gorm v1.9.2 h1:lCvgEaqe/HVE+tjAR2mt4HbbHAZsQOv3XAZiEZV37iw= github.com/jinzhu/gorm v1.9.2/go.mod h1:Vla75njaFJ8clLU1W44h34PjIkijhjHIYnZxMqCdxqo= github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a h1:eeaG9XMUvRBYXJi4pg1ZKM7nxc5AfXfojeLLW7O5J3k= github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v0.0.0-20181116074157-8ec929ed50c3 h1:xvj06l8iSwiWpYgm8MbPp+naBg+pwfqmdXabzqPCn/8= +github.com/jinzhu/now v0.0.0-20181116074157-8ec929ed50c3/go.mod h1:oHTiXerJ20+SfYcrdlBO7rzZRJWGwSTQ0iUY2jI6Gfc= +github.com/kisielk/errcheck v1.2.0 h1:reN85Pxc5larApoH1keMBiu2GWtPqXQ1nc9gx+jOU+E= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/labstack/echo v3.3.5+incompatible h1:9PfxPUmasKzeJor9uQTaXLT6WUG/r+vSTmvXxvv3JO4= github.com/labstack/echo v3.3.5+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= @@ -61,18 +77,23 @@ github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 h1:gKMu1Bf6QI github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4/go.mod h1:50wTf68f99/Zt14pr046Tgt3Lp2vLyFZKzbFXTOabXw= golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc h1:F5tKCVGp+MUAHhKp5MZtGqAlGX3+oCsiL1Q629FL90M= golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190110200230-915654e7eabc h1:Yx9JGxI1SBhVLFjpAkWMaO1TF+xyqtHLjZpvQboJGiM= golang.org/x/net v0.0.0-20190110200230-915654e7eabc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563 h1:NIou6eNFigscvKJmsbyez16S2cIS6idossORlFtSt2E= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/genproto v0.0.0-20170818100345-ee236bd376b0/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= @@ -80,7 +101,12 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190128043916-71123fcbb8fe h1:/GZ/onp6W295MEgrIwtlbnxmFSKGavFp7/D7tMVyuaM= +honnef.co/go/tools v0.0.0-20190128043916-71123fcbb8fe/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/helloworld/greeter_server.go b/internal/helloworld/greeter_server.go index 285bfdb0..5d2129d7 100644 --- a/internal/helloworld/greeter_server.go +++ b/internal/helloworld/greeter_server.go @@ -27,7 +27,7 @@ var Bidi CallType = "bidi" // Greeter implements the GreeterServer for tests type Greeter struct { streamData []*HelloReply - mutex *sync.Mutex + mutex *sync.RWMutex callCounts map[CallType]int } @@ -111,7 +111,9 @@ func (s *Greeter) ResetCounters() { // GetCount gets the count for specific call type func (s *Greeter) GetCount(key CallType) int { + s.mutex.RLock() val, ok := s.callCounts[key] + s.mutex.RUnlock() if ok { return val } @@ -133,5 +135,5 @@ func NewGreeter() *Greeter { m[ClientStream] = 0 m[Bidi] = 0 - return &Greeter{streamData: streamData, callCounts: m, mutex: &sync.Mutex{}} + return &Greeter{streamData: streamData, callCounts: m, mutex: &sync.RWMutex{}} } diff --git a/internal/tools/tools.go b/internal/tools/tools.go new file mode 100644 index 00000000..090ff2a1 --- /dev/null +++ b/internal/tools/tools.go @@ -0,0 +1,10 @@ +// +build tools + +// Package tools blank imports Golang tools we use as part of the build. +package tools + +import ( + _ "github.com/golang/lint/golint" // tool + _ "github.com/kisielk/errcheck" // tool + _ "honnef.co/go/tools/cmd/staticcheck" // tool +)