From 38327bac99039e8050df976f469093081722421b Mon Sep 17 00:00:00 2001 From: Remco Beckers Date: Sun, 22 Dec 2019 16:32:57 +0100 Subject: [PATCH 1/4] Switch to go modules --- Gopkg.lock | 17 ----------------- Gopkg.toml | 8 -------- Makefile | 1 - build-env.sh | 8 -------- go.mod | 5 +++++ go.sum | 2 ++ 6 files changed, 7 insertions(+), 34 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml create mode 100644 go.mod create mode 100644 go.sum diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index a89bb45..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,17 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:d3ffbc45dfe6929a4ba313464c2d761d96325d306eda29512da56c034db2a4dd" - name = "github.com/sony/gobreaker" - packages = ["."] - pruneopts = "UT" - revision = "b2a34562d02c4d5fd6645399c69e00141fb24e5a" - version = "0.4.0" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = ["github.com/sony/gobreaker"] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 6538be0..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,8 +0,0 @@ - -[[constraint]] - name = "github.com/sony/gobreaker" - version = "0.4.0" - -[prune] - go-tests = true - unused-packages = true diff --git a/Makefile b/Makefile index 0761c89..b0ac7c6 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,5 @@ clean: build: source build-env.sh && \ cd $(GO_PROJECT_PATH) && \ - dep ensure && \ mkdir -p build && \ GOOS=linux GOARCH=amd64 go build -o build/trafficmirror diff --git a/build-env.sh b/build-env.sh index 5cd18a5..991b512 100755 --- a/build-env.sh +++ b/build-env.sh @@ -1,12 +1,4 @@ # use with source -export GL_URL=github.com/rb3ckers -export GO_PROJECT_NAMESPACE=trafficmirror -if [ ! -d $(pwd)/.go ] -then -mkdir -p $(pwd)/.go/src/$GL_URL -ln -s $(pwd) $(pwd)/.go/src/$GL_URL/$GO_PROJECT_NAMESPACE -fi export GOPATH=$(pwd)/.go export GOBIN=$GOPATH/bin export PATH=$GOBIN:$PATH -export GO_PROJECT_PATH=$(pwd)/.go/src/$GL_URL/$GO_PROJECT_NAMESPACE diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2280177 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/rb3ckers/trafficmirror + +go 1.12 + +require github.com/sony/gobreaker v0.0.0-20180905101324-b2a34562d02c diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..1abe5c1 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/sony/gobreaker v0.0.0-20180905101324-b2a34562d02c h1:7EMc5KMRVlkzEyK5n4YqdPEsmO+6AlAGCJiqnqW6n2Y= +github.com/sony/gobreaker v0.0.0-20180905101324-b2a34562d02c/go.mod h1:XvpJiTD8NibaH7z0NzyfhR1+NQDtR9F/x92xheTwC9k= From e693e300c4b7157555e80410e0e5f3b9c3d47db8 Mon Sep 17 00:00:00 2001 From: Remco Beckers Date: Sun, 22 Dec 2019 16:49:12 +0100 Subject: [PATCH 2/4] More cleanup --- Dockerfile | 8 +++----- Makefile | 10 ---------- build-env.sh | 4 ---- 3 files changed, 3 insertions(+), 19 deletions(-) delete mode 100644 Makefile delete mode 100755 build-env.sh diff --git a/Dockerfile b/Dockerfile index fe86de8..42d398b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,17 +2,15 @@ # Builder # ########### -FROM golang:1.11-alpine AS builder +FROM golang:1.12-alpine AS builder RUN apk add --no-cache git -COPY . $GOPATH/src/github.com/rb3ckers/trafficmirror +COPY . /build -WORKDIR $GOPATH/src/github.com/rb3ckers/trafficmirror +WORKDIR /build RUN set -ex \ - && go get -u -v github.com/golang/dep/cmd/dep \ - && dep ensure -v \ && GOOS=linux GOARCH=amd64 go build -o /build/trafficmirror RUN /build/trafficmirror --help diff --git a/Makefile b/Makefile deleted file mode 100644 index b0ac7c6..0000000 --- a/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -SHELL := /bin/bash - -clean: - rm -rf build - -build: - source build-env.sh && \ - cd $(GO_PROJECT_PATH) && \ - mkdir -p build && \ - GOOS=linux GOARCH=amd64 go build -o build/trafficmirror diff --git a/build-env.sh b/build-env.sh deleted file mode 100755 index 991b512..0000000 --- a/build-env.sh +++ /dev/null @@ -1,4 +0,0 @@ -# use with source -export GOPATH=$(pwd)/.go -export GOBIN=$GOPATH/bin -export PATH=$GOBIN:$PATH From ccba9b454c5e4dd3aad41b11079568145810c967 Mon Sep 17 00:00:00 2001 From: Remco Beckers Date: Sun, 22 Dec 2019 17:14:14 +0100 Subject: [PATCH 3/4] Bump go breaker version --- go.mod | 2 +- go.sum | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2280177..d8cd89c 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/rb3ckers/trafficmirror go 1.12 -require github.com/sony/gobreaker v0.0.0-20180905101324-b2a34562d02c +require github.com/sony/gobreaker v0.4.1 diff --git a/go.sum b/go.sum index 1abe5c1..2ce709a 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,8 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sony/gobreaker v0.0.0-20180905101324-b2a34562d02c h1:7EMc5KMRVlkzEyK5n4YqdPEsmO+6AlAGCJiqnqW6n2Y= github.com/sony/gobreaker v0.0.0-20180905101324-b2a34562d02c/go.mod h1:XvpJiTD8NibaH7z0NzyfhR1+NQDtR9F/x92xheTwC9k= +github.com/sony/gobreaker v0.4.1 h1:oMnRNZXX5j85zso6xCPRNPtmAycat+WcoKbklScLDgQ= +github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= From be23530445f4a339de4d373ad60bab2d074b7381 Mon Sep 17 00:00:00 2001 From: Remco Beckers Date: Mon, 13 Jan 2020 18:17:37 +0100 Subject: [PATCH 4/4] Add pre-commit hooks for go --- .pre-commit-config.yaml | 15 +++++++++++++++ README.md | 8 ++++++++ custom-hooks/go-mod-tidy.sh | 4 ++++ go.sum | 5 +++-- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100755 custom-hooks/go-mod-tidy.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f16ff44 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +- repo: git://github.com/dnephin/pre-commit-golang + rev: master + hooks: + - id: go-fmt + - id: go-vet + - id: go-imports + - id: validate-toml +- repo: local + hooks: + - id: go-mod-tidy + name: 'go mod tidy' + entry: custom-hooks/go-mod-tidy.sh + files: '(\.go)|(\.mod)|(\.sum)$' + language: 'script' + description: "Runs `gofmt`, requires golang" \ No newline at end of file diff --git a/README.md b/README.md index cc2334c..83b1e64 100644 --- a/README.md +++ b/README.md @@ -58,3 +58,11 @@ The list command should become: ## Error behavior While a target is available and responding to requests it will keep on receiving mirrored data. However when it starts failing, either returning errors or maybe it is down, the target will temporarily not receive any traffic anymore. After a minute (see the `retry-after` option) it will be retried with a single request, if this succeeds it will start receiving traffic again. If a target is persistently failing for 30 minutes (see `fail-after` option) it will be automatically removed from the set of targets and will need to be added manually again if the situation has been resolved. + + +# Developing +This repository uses Pre-commit to run some basic go linting and checks. Please install it when developing. +``` +brew install pre-commit # install pre-commit if you haven't already +pre-commit install # install the hooks in your local clone +``` \ No newline at end of file diff --git a/custom-hooks/go-mod-tidy.sh b/custom-hooks/go-mod-tidy.sh new file mode 100755 index 0000000..23e2009 --- /dev/null +++ b/custom-hooks/go-mod-tidy.sh @@ -0,0 +1,4 @@ +#! /bin/bash +set -e + +go mod tidy diff --git a/go.sum b/go.sum index 2ce709a..eaabafa 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,9 @@ +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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sony/gobreaker v0.0.0-20180905101324-b2a34562d02c h1:7EMc5KMRVlkzEyK5n4YqdPEsmO+6AlAGCJiqnqW6n2Y= -github.com/sony/gobreaker v0.0.0-20180905101324-b2a34562d02c/go.mod h1:XvpJiTD8NibaH7z0NzyfhR1+NQDtR9F/x92xheTwC9k= github.com/sony/gobreaker v0.4.1 h1:oMnRNZXX5j85zso6xCPRNPtmAycat+WcoKbklScLDgQ= github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=