From 451a1d1f7e969162699292c2ffe0781e6c2f2bf9 Mon Sep 17 00:00:00 2001 From: Darshil Chanpura Date: Sat, 18 Sep 2021 11:41:38 +0530 Subject: [PATCH] Added .drone.yml for releasing and fixes in Makefile + linter changes --- .drone.yml | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 5 ++- proxy/proxy.go | 7 ++++ 3 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..fb5ba2c --- /dev/null +++ b/.drone.yml @@ -0,0 +1,95 @@ +--- +kind: pipeline +type: docker +name: default + +platform: + os: linux + arch: amd64 + +workspace: + path: /drone/src + +steps: +- name: prerequisites + image: golang + commands: + - mkdir -p release + - go install honnef.co/go/tools/cmd/staticcheck@latest + - go install github.com/fzipp/gocyclo/cmd/gocyclo@latest + volumes: + - name: cache + path: /go + +- name: test + image: golang + commands: + - go test -v -race ./... + - go vet ./... + - staticcheck ./... + - gocyclo -over 19 $(find . -iname '*.go' -type f | grep -v /vendor/) + - golint -set_exit_status ./... + volumes: + - name: cache + path: /go + +- name: build-darwin + image: golang + commands: + - mkdir -p release/darwin + - GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/darwin/dumb-http cmd/dumb-http/main.go + - tar -czf release/dumb-http-${DRONE_TAG:-latest}-darwin-amd64.tar.gz README.md -C release/darwin/ dumb-http + - GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/darwin/dumb-http cmd/dumb-http/main.go + - tar -czf release/dumb-http-${DRONE_TAG:-latest}-darwin-arm64.tar.gz README.md -C release/darwin/ dumb-http + +- name: build-windows + image: golang + commands: + - mkdir -p release/windows + - GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/windows/dumb-http cmd/dumb-http/main.go + - tar -czf release/dumb-http-${DRONE_TAG:-latest}-windows-amd64.tar.gz README.md -C release/windows/ dumb-http + +- name: build-linux + image: golang + commands: + - mkdir -p release/linux + - GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/linux/dumb-http cmd/dumb-http/main.go + - tar -czf release/dumb-http-${DRONE_TAG:-latest}-linux-amd64.tar.gz README.md -C release/linux/ dumb-http + - GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/linux/dumb-http cmd/dumb-http/main.go + - tar -czf release/dumb-http-${DRONE_TAG:-latest}-linux-arm64.tar.gz README.md -C release/linux/ dumb-http + +- name: dummy-check + image: golang + commands: + - ls -lah release/ + - ls -lah release/* + depends_on: + - build-linux + - build-darwin + - build-windows + +- name: gitea-release + image: plugins/gitea-release + settings: + api_key: + from_secret: gitea_token + base_url: https://git.dcpri.me + checksum: + - sha256 + files: + - release/*.tar.gz + - release/debs/*.deb + title: Version ${DRONE_TAG/v/} + when: + event: + - tag + depends_on: + - build-linux + - build-darwin + - build-windows + +--- +kind: signature +hmac: 679972f18fba9f3c277e6642a0456d9b94a59dbd0f5ae1755325ab093045c713 + +... diff --git a/Makefile b/Makefile index 305f580..e34ea29 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,8 @@ os = $(word 1, $@) bootstrap: @mkdir -p release - go get golang.org/x/lint # Linter - go get honnef.co/go/tools/cmd/staticcheck # Badass static analyzer/linter - go get github.com/fzipp/gocyclo # Cyclomatic complexity check + go install honnef.co/go/tools/cmd/staticcheck@latest # Badass static analyzer/linter + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest # Cyclomatic complexity check test: go test -v -race $(PKGS) # Normal Test diff --git a/proxy/proxy.go b/proxy/proxy.go index 8a67e01..4a14697 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -6,6 +6,9 @@ import ( "net/url" ) +// Proxy struct contains the mux for handling paths, rp for conditionally +// doing a reverse proxy to upstream and root as root directory for serving +// static content. type Proxy struct { mux *http.ServeMux @@ -13,6 +16,8 @@ type Proxy struct { root string } +// New will return a Proxy struct with a new server mux and +// set reverse proxy Proxy.rp in case if the upstream is not empty. func New(upstream, root string) (*Proxy, error) { if upstream == "" { return &Proxy{ @@ -32,6 +37,8 @@ func New(upstream, root string) (*Proxy, error) { }, nil } +// Routes will set routes based on the values of Proxy.rp and +// by default set / to file server. func (p *Proxy) Routes(proxyPath string, stripPrefix bool) { if p.rp == nil { p.mux.Handle("/", http.FileServer(http.Dir(p.root)))