diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..cc031e5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +Makefile linguist-vendored diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ecc177 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.project +.classpath +.idea +.cache +.DS_Store +*.im? +target +work +bin/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..49e1bc3 --- /dev/null +++ b/Makefile @@ -0,0 +1,68 @@ +SHELL := /bin/bash +GO := GO15VENDOREXPERIMENT=1 go +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 +VENDOR_DIR=vendor + +all: build + +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 + +full: $(PKGS) + +install: + GOBIN=${GOPATH}/bin $(GO) install -ldflags $(BUILDFLAGS) $(MAIN_GO) + +fmt: + @FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)` + @([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true + +clean: + rm -rf build release + +linux: + CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO) + +.PHONY: release clean + +FGT := $(GOPATH)/bin/fgt +$(FGT): + go get github.com/GeertJohan/fgt + +GOLINT := $(GOPATH)/bin/golint +$(GOLINT): + go get github.com/golang/lint/golint + +$(PKGS): $(GOLINT) $(FGT) + @echo "LINTING" + @$(FGT) $(GOLINT) $(GOPATH)/src/$@/*.go + @echo "VETTING" + @go vet -v $@ + @echo "TESTING" + @go test -v $@ + +.PHONY: lint +lint: vendor | $(PKGS) $(GOLINT) # ❷ + @cd $(BASE) && ret=0 && for pkg in $(PKGS); do \ + test -z "$$($(GOLINT) $$pkg | tee /dev/stderr)" || ret=1 ; \ + done ; exit $$ret + +watch: + reflex -r "\.go$" -R "vendor.*" make skaffold-run + +skaffold-run: build + skaffold run -p dev diff --git a/README.md b/README.md new file mode 100644 index 0000000..f6bd895 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# golang-http diff --git a/curlloop.sh b/curlloop.sh new file mode 100755 index 0000000..581f919 --- /dev/null +++ b/curlloop.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +export APP="$1" +echo "curling URL $APP in a loop..." + +while true +do + curl $APP + sleep 2 +done diff --git a/main.go b/main.go new file mode 100644 index 0000000..c85a82a --- /dev/null +++ b/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func handler(w http.ResponseWriter, r *http.Request) { + title := "Jenkins X golang http example" + + from := "" + if r.URL != nil { + from = r.URL.String() + } + if from != "/favicon.ico" { + log.Printf("title: %s\n", title) + } + + fmt.Fprintf(w, "Hello from: "+title+"\n") +} + +func main() { + http.HandleFunc("/", handler) + http.ListenAndServe(":8080", nil) +} diff --git a/watch.sh b/watch.sh new file mode 100755 index 0000000..49dce24 --- /dev/null +++ b/watch.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +make skaffold-run +reflex -r "\.go$" -R "vendor.*" make skaffold-run