diff --git a/.gitignore b/.gitignore index 8ecc177..9a7297f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ *.im? target work -bin/ \ No newline at end of file +bin/ + +coverage.txt +coverage.html \ No newline at end of file diff --git a/Makefile b/Makefile index 49e1bc3..f2c2bd4 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,16 @@ SHELL := /bin/bash GO := GO15VENDOREXPERIMENT=1 go +GOPATH := $(shell go env GOPATH) NAME := REPLACE_ME_APP_NAME OS := $(shell uname) MAIN_GO := main.go ROOT_PACKAGE := $(GIT_PROVIDER)/$(ORG)/$(NAME) GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/') -PACKAGE_DIRS := $(shell $(GO) list ./... | grep -v /vendor/) PKGS := $(shell go list ./... | grep -v /vendor | grep -v generated) PKGS := $(subst :,_,$(PKGS)) BUILDFLAGS := '' CGO_ENABLED = 0 +MODULE_ENABLED = on VENDOR_DIR=vendor all: build @@ -19,8 +20,13 @@ check: fmt build test build: CGO_ENABLED=$(CGO_ENABLED) $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO) -test: - CGO_ENABLED=$(CGO_ENABLED) $(GO) test $(PACKAGE_DIRS) -test.v +ACC := $(GOPATH)/bin/go-acc +$(ACC): #leave modules off for this tool download so go.mod not updated + GO111MODULE=off $(GO) get github.com/ory/go-acc + +test: $(ACC) + GO111MODULE=$(MODULE_ENABLED) $(ACC) -o coverage.txt $(PKGS) + $(GO) tool cover -html=coverage.txt -o coverage.html full: $(PKGS) @@ -28,7 +34,8 @@ install: GOBIN=${GOPATH}/bin $(GO) install -ldflags $(BUILDFLAGS) $(MAIN_GO) fmt: - @FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)` + @FORMATTED=`$(GO) fmt $(PKGS)` + printf "$(FORMATTED)" @([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true clean: @@ -41,11 +48,13 @@ linux: FGT := $(GOPATH)/bin/fgt $(FGT): - go get github.com/GeertJohan/fgt + #leave modules off for this tool download so go.mod not updated + GO111MODULE=off go get github.com/GeertJohan/fgt GOLINT := $(GOPATH)/bin/golint $(GOLINT): - go get github.com/golang/lint/golint + #leave modules off for this tool download so go.mod not updated + GO111MODULE=off go get github.com/golang/lint/golint $(PKGS): $(GOLINT) $(FGT) @echo "LINTING" @@ -56,7 +65,7 @@ $(PKGS): $(GOLINT) $(FGT) @go test -v $@ .PHONY: lint -lint: vendor | $(PKGS) $(GOLINT) # ❷ +lint: $(PKGS) $(GOLINT) @cd $(BASE) && ret=0 && for pkg in $(PKGS); do \ test -z "$$($(GOLINT) $$pkg | tee /dev/stderr)" || ret=1 ; \ done ; exit $$ret diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..57d91a5 --- /dev/null +++ b/go.mod @@ -0,0 +1 @@ +module github.com/jenkins-x-quickstarts/golang-http diff --git a/main.go b/main.go index c85a82a..2310c80 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ func handler(w http.ResponseWriter, r *http.Request) { log.Printf("title: %s\n", title) } - fmt.Fprintf(w, "Hello from: "+title+"\n") + fmt.Fprintf(w, "Hello from: %s\n", title) } func main() {