diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..04a32e3 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,24 @@ +run: + tests: false + timeout: 5m +linters: + enable-all: true + disable: + - exhaustive + - exhaustivestruct + - funlen + - gochecknoglobals + - gochecknoinits + - gocognit + - gocyclo + - goerr113 + - gomnd + - interfacer + - nestif + - noctx + - nlreturn + - scopelint + - wrapcheck + - wsl + - gofumpt + - godox \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 3cb75c3..4da7062 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,26 +2,24 @@ sudo: false language: go go: - - "1.11.x" - - "1.12.x" - - "1.13.x" + - "1.14.x" + - "1.15.x" - "1.x" env: - - GO111MODULE=on GOFLAGS=-mod=readonly GOPROXY=https://proxy.golang.org + - GO111MODULE=on GOPROXY=https://proxy.golang.org cache: directories: - $GOPATH/pkg/mod before_install: + - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin ${GOLANGCI_LINT_VERSION} + - GO111MODULE=off go get -u github.com/mattn/goveralls # Use `go install` in Go1.16 - go mod download - - go get -u golang.org/x/lint/golint - - go get github.com/mattn/goveralls script: - - golint ./... - - go vet ./... + - golangci-lint run ./... - go test -covermode=count -coverprofile=profile.cov ./... - goveralls -coverprofile=profile.cov -service=travis-ci diff --git a/cache/cache.go b/cache/cache.go index 5efb5a1..ac4f6af 100755 --- a/cache/cache.go +++ b/cache/cache.go @@ -5,12 +5,6 @@ import ( "time" ) -type key int - -const ( - ctxKey key = iota -) - var ( // ErrCacheMiss is returned if a Get failed because the item wasn't present. ErrCacheMiss = errors.New("cache: miss") diff --git a/cache/item.go b/cache/item.go index f5d4bf7..a44dc90 100755 --- a/cache/item.go +++ b/cache/item.go @@ -10,7 +10,7 @@ type Decoder interface { String(interface{}) (string, error) } -// Item represents an item to be returned or stored in the cache +// Item represents an item to be returned or stored in the cache. type Item struct { dec Decoder Value interface{} diff --git a/go.mod b/go.mod index a76a9db..05f7fdb 100644 --- a/go.mod +++ b/go.mod @@ -1,27 +1,10 @@ module github.com/hamba/pkg -go 1.11 +go 1.14 require ( - github.com/go-kit/kit v0.9.0 // indirect github.com/go-zoo/bone v1.3.0 - github.com/google/go-cmp v0.3.1 // indirect - github.com/hamba/statter v1.2.0 // indirect github.com/hamba/timex v1.0.1 github.com/json-iterator/go v1.1.10 - github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect - github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect - github.com/pkg/errors v0.8.1 // indirect - github.com/prometheus/client_golang v1.1.0 // indirect - github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect - github.com/ryanuber/go-glob v1.0.0 - github.com/sirupsen/logrus v1.4.2 // indirect - github.com/stretchr/objx v0.2.0 // indirect github.com/stretchr/testify v1.6.1 - golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 // indirect - golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect - golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // indirect - golang.org/x/text v0.3.2 // indirect - golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f // indirect - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) diff --git a/go.sum b/go.sum index 3e0b079..133c984 100644 --- a/go.sum +++ b/go.sum @@ -1,131 +1,30 @@ -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cactus/go-statsd-client v3.1.1+incompatible/go.mod h1:cMRcwZDklk7hXp+Law83urTHUiHMzCev/r4JMYr/zU0= 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/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-zoo/bone v0.0.0-20190117145001-d7ce1372afa7 h1:9j1EAzjykFGj2YY/+Y1TcEQMf5eAEOzbnPUMT9YYb5g= -github.com/go-zoo/bone v0.0.0-20190117145001-d7ce1372afa7/go.mod h1:HI3Lhb7G3UQcAwEhOJ2WyNcsFtQX1WYHa0Hl4OBbhW8= github.com/go-zoo/bone v1.3.0 h1:PY6sHq37FnQhj+4ZyqFIzJQHvrrGx0GEc3vTZZC/OsI= github.com/go-zoo/bone v1.3.0/go.mod h1:HI3Lhb7G3UQcAwEhOJ2WyNcsFtQX1WYHa0Hl4OBbhW8= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/hamba/statter v1.2.0 h1:U4LO5T1KFFaqAH+vKRUbVGp/02ece03VlB43iSxClrg= -github.com/hamba/statter v1.2.0/go.mod h1:WejmlyR9cUs+uDkJz4K6n2jRBVvHkYuaObsW59SlgZQ= -github.com/hamba/timex v1.0.0 h1:sZS2ayYoXTFZI+4VgQEM/+vWkkKKwRmUjVPaQixkqvY= -github.com/hamba/timex v1.0.0/go.mod h1:Vxcwh2yr1/vkc0XVBfQSScn/MBsOKdatr6fVyj+isuo= github.com/hamba/timex v1.0.1 h1:Qefttpp1WRjv2irFi1uMvfM+CmivG/7YSkMlG/WKHWQ= github.com/hamba/timex v1.0.1/go.mod h1:lUd4hx+gOnT4D9WP7mzJyVaG/B25a+TaPq4nr2AiVf4= -github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE= -github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo= -github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= -github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= -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/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= -github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= -github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.0 h1:jlIyCplCJFULU/01vCkhKuTyc3OorI3bJFuw6obfgho= -github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190820033707-85edb9ef3283/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +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/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/httpx/httptest/server.go b/httpx/httptest/server.go deleted file mode 100755 index bd76db6..0000000 --- a/httpx/httptest/server.go +++ /dev/null @@ -1,174 +0,0 @@ -/* -Package httptest provides utilities for HTTP testing. - -Deprecated: Use github.com/hamba/testutils instead. - -Example Server Usage: - - import ( - "net/http" - "testing" - - "github.com/hamba/pkg/httpx/httptest" - ) - - func TestSomething(t *testing.T) { - s := httptest.NewServer(t) - s.On(http.MethodGet, "/your/endpoint").Times(2).ReturnsString(http.StatusOK, "some return") - defer s.Close() - - // Call the server - - s.AssertExpectations() - } -*/ -package httptest - -import ( - "net/http" - "net/http/httptest" - "testing" - - "github.com/ryanuber/go-glob" -) - -const ( - // Anything is used where the expectation should not be considered. - Anything = "httpx/httptest.Anything" -) - -// Expectation represents an http request expectation. -type Expectation struct { - method string - path string - - fn http.HandlerFunc - - headers []string - body []byte - status int - - times int -} - -// Times sets the number of times the request can be made. -func (e *Expectation) Times(times int) *Expectation { - e.times = times - - return e -} - -// Header sets the HTTP headers that should be returned. -func (e *Expectation) Header(k, v string) *Expectation { - e.headers = append(e.headers, k, v) - - return e -} - -// Handle sets the HTTP handler function to be run on the request. -func (e *Expectation) Handle(fn http.HandlerFunc) { - e.fn = fn -} - -// ReturnsStatus sets the HTTP stats code to return. -func (e *Expectation) ReturnsStatus(status int) { - e.body = []byte{} - e.status = status -} - -// Returns sets the HTTP stats and body bytes to return. -func (e *Expectation) Returns(status int, body []byte) { - e.body = body - e.status = status -} - -// ReturnsString sets the HTTP stats and body string to return. -func (e *Expectation) ReturnsString(status int, body string) { - e.body = []byte(body) - e.status = status -} - -// Server represents a mock http server. -type Server struct { - t *testing.T - srv *httptest.Server - - expect []*Expectation -} - -// NewServer creates a new mock http server. -func NewServer(t *testing.T) *Server { - srv := &Server{ - t: t, - } - srv.srv = httptest.NewServer(http.HandlerFunc(srv.handler)) - - return srv -} - -// URL returns the url of the mock server. -func (s *Server) URL() string { - return s.srv.URL -} - -func (s *Server) handler(w http.ResponseWriter, r *http.Request) { - method := r.Method - path := r.URL.Path - for i, exp := range s.expect { - if exp.method != method && exp.method != Anything { - continue - } - - if exp.path != Anything && !glob.Glob(exp.path, path) { - continue - } - - for i := 0; i < len(exp.headers); i += 2 { - w.Header().Add(exp.headers[i], exp.headers[i+1]) - } - - if exp.fn != nil { - exp.fn(w, r) - } else { - w.WriteHeader(exp.status) - if len(exp.body) > 0 { - w.Write(exp.body) - } - } - - exp.times-- - if exp.times == 0 { - s.expect = append(s.expect[:i], s.expect[i+1:]...) - } - return - } - - s.t.Errorf("Unexpected call to %s %s", method, path) -} - -// On creates an expectation of a request on the server. -func (s *Server) On(method, path string) *Expectation { - exp := &Expectation{ - method: method, - path: path, - times: -1, - status: 200, - } - s.expect = append(s.expect, exp) - - return exp -} - -// AssertExpectations asserts all expectations have been met. -func (s *Server) AssertExpectations() { - for _, exp := range s.expect { - if exp.times > 0 || exp.times == -1 { - s.t.Errorf("mock: server: Expected a call to %s %s but got none", exp.method, exp.path) - } - } -} - -// Close closes the server. -func (s *Server) Close() { - s.srv.Close() -} diff --git a/httpx/httptest/server_test.go b/httpx/httptest/server_test.go deleted file mode 100755 index fb7add4..0000000 --- a/httpx/httptest/server_test.go +++ /dev/null @@ -1,229 +0,0 @@ -package httptest_test - -import ( - "bytes" - "io/ioutil" - "net/http" - "testing" - - "github.com/hamba/pkg/httpx/httptest" - "github.com/stretchr/testify/assert" -) - -func TestServer_HandlesExpectation(t *testing.T) { - s := httptest.NewServer(t) - defer s.Close() - - s.On("GET", "/test/path") - - res, err := http.Get(s.URL() + "/test/path") - assert.NoError(t, err) - assert.Equal(t, 200, res.StatusCode) -} - -func TestServer_HandlesAnythingMethodExpectation(t *testing.T) { - s := httptest.NewServer(t) - defer s.Close() - - s.On(httptest.Anything, "/test/path") - - res, err := http.Post(s.URL()+"/test/path", "text/plain", bytes.NewReader([]byte{})) - assert.NoError(t, err) - assert.Equal(t, 200, res.StatusCode) -} - -func TestServer_HandlesAnythingPathExpectation(t *testing.T) { - s := httptest.NewServer(t) - defer s.Close() - - s.On("GET", httptest.Anything) - - res, err := http.Get(s.URL() + "/test/path") - assert.NoError(t, err) - assert.Equal(t, 200, res.StatusCode) -} - -func TestServer_HandlesWildcardPathExpectation(t *testing.T) { - s := httptest.NewServer(t) - defer s.Close() - - s.On("GET", "/test/*") - - res, err := http.Get(s.URL() + "/test/path") - assert.NoError(t, err) - assert.Equal(t, 200, res.StatusCode) -} - -func TestServer_HandlesUnexpectedMethodRequest(t *testing.T) { - mockT := new(testing.T) - defer func() { - if !mockT.Failed() { - t.Error("Expected error when no expectation on request") - } - - }() - - s := httptest.NewServer(mockT) - defer s.Close() - - s.On("POST", "/") - - http.Get(s.URL() + "/test/path") -} - -func TestServer_HandlesUnexpectedPathRequest(t *testing.T) { - mockT := new(testing.T) - defer func() { - if !mockT.Failed() { - t.Error("Expected error when no expectation on request") - } - - }() - - s := httptest.NewServer(mockT) - defer s.Close() - s.On("GET", "/foobar") - - s.On("GET", "/") - - http.Get(s.URL() + "/test/path") -} - -func TestServer_HandlesExpectationNTimes(t *testing.T) { - mockT := new(testing.T) - defer func() { - if !mockT.Failed() { - t.Error("Expected error when expectation times used") - } - - }() - - s := httptest.NewServer(mockT) - defer s.Close() - s.On("GET", "/test/path").Times(2) - - http.Get(s.URL() + "/test/path") - http.Get(s.URL() + "/test/path") - http.Get(s.URL() + "/test/path") -} - -func TestServer_HandlesExpectationUnlimitedTimes(t *testing.T) { - mockT := new(testing.T) - defer func() { - if mockT.Failed() { - t.Error("Unexpected error on request") - } - - }() - - s := httptest.NewServer(mockT) - defer s.Close() - s.On("GET", "/test/path") - - http.Get(s.URL() + "/test/path") - http.Get(s.URL() + "/test/path") -} - -func TestServer_ExpectationReturnsBodyBytes(t *testing.T) { - s := httptest.NewServer(t) - defer s.Close() - - s.On("GET", "/test/path").Returns(400, []byte("test")) - - res, err := http.Get(s.URL() + "/test/path") - assert.NoError(t, err) - assert.Equal(t, 400, res.StatusCode) - b, _ := ioutil.ReadAll(res.Body) - assert.Equal(t, []byte("test"), b) - - res.Body.Close() -} - -func TestServer_ExpectationReturnsBodyString(t *testing.T) { - s := httptest.NewServer(t) - defer s.Close() - - s.On("GET", "/test/path").ReturnsString(400, "test") - - res, err := http.Get(s.URL() + "/test/path") - assert.NoError(t, err) - assert.Equal(t, 400, res.StatusCode) - b, _ := ioutil.ReadAll(res.Body) - assert.Equal(t, []byte("test"), b) - - res.Body.Close() -} - -func TestServer_ExpectationReturnsStatusCode(t *testing.T) { - s := httptest.NewServer(t) - defer s.Close() - - s.On("GET", "/test/path").ReturnsStatus(400) - - res, err := http.Get(s.URL() + "/test/path") - assert.NoError(t, err) - assert.Equal(t, 400, res.StatusCode) - b, _ := ioutil.ReadAll(res.Body) - assert.Len(t, b, 0) - - res.Body.Close() -} - -func TestServer_ExpectationReturnsHeaders(t *testing.T) { - s := httptest.NewServer(t) - defer s.Close() - - s.On("GET", "/test/path").Header("foo", "bar").ReturnsStatus(200) - - res, err := http.Get(s.URL() + "/test/path") - assert.NoError(t, err) - v := res.Header.Get("foo") - assert.Equal(t, "bar", v) - - res.Body.Close() -} - -func TestServer_ExpectationUsesHandleFunc(t *testing.T) { - s := httptest.NewServer(t) - defer s.Close() - - s.On("GET", "/test/path").Handle(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(400) - }) - - res, err := http.Get(s.URL() + "/test/path") - assert.NoError(t, err) - assert.Equal(t, 400, res.StatusCode) -} - -func TestServer_AssertExpectationsOnUnlimited(t *testing.T) { - mockT := new(testing.T) - defer func() { - if !mockT.Failed() { - t.Error("Expected error when asserting expectations") - } - - }() - - s := httptest.NewServer(mockT) - defer s.Close() - s.On("POST", "/") - - s.AssertExpectations() -} - -func TestServer_AssertExpectationsOnNTimes(t *testing.T) { - mockT := new(testing.T) - defer func() { - if !mockT.Failed() { - t.Error("Expected error when asserting expectations") - } - - }() - - s := httptest.NewServer(mockT) - defer s.Close() - s.On("POST", "/").Times(1) - - s.AssertExpectations() -} diff --git a/httpx/json.go b/httpx/json.go index d9d2510..6f31a05 100755 --- a/httpx/json.go +++ b/httpx/json.go @@ -3,7 +3,7 @@ package httpx import ( "net/http" - "github.com/json-iterator/go" + jsoniter "github.com/json-iterator/go" ) const ( diff --git a/httpx/middleware/stats.go b/httpx/middleware/stats.go index 8f0a49d..6b88694 100755 --- a/httpx/middleware/stats.go +++ b/httpx/middleware/stats.go @@ -8,7 +8,7 @@ import ( "github.com/hamba/timex/mono" ) -// TagsFunc returns a set of tags from a request +// TagsFunc returns a set of tags from a request. type TagsFunc func(*http.Request) []string // DefaultTags extracts the method and path from the request. diff --git a/log/logger.go b/log/logger.go index 488703c..4afe6b2 100644 --- a/log/logger.go +++ b/log/logger.go @@ -6,12 +6,6 @@ import ( "os" ) -type key int - -const ( - ctxKey key = iota -) - var ( // Null is the null Logger instance. Null = &nullLogger{} diff --git a/retry/retry.go b/retry/retry.go index 79a994c..6a62ff3 100755 --- a/retry/retry.go +++ b/retry/retry.go @@ -24,6 +24,7 @@ func ExponentialPolicy(attempts int, sleep time.Duration) Policy { } } +// Next returns the next wait time or false. func (p *exponentialPolicy) Next() (time.Duration, bool) { p.attempts-- if p.attempts <= 0 { @@ -37,7 +38,7 @@ func (p *exponentialPolicy) Next() (time.Duration, bool) { return p.sleep, true } -// Run executes the function while the Policy allows +// Run executes the function while the Policy allows. // until it returns nil or Stop. func Run(p Policy, fn func() error) error { if p == nil { @@ -45,14 +46,15 @@ func Run(p Policy, fn func() error) error { } if err := fn(); err != nil { - if s, ok := err.(stop); ok { + s := stop{} + if errors.As(err, &s) { return s.error } if sleep, ok := p.Next(); ok { time.Sleep(sleep) - Run(p, fn) + _ = Run(p, fn) } return err diff --git a/stats/statter.go b/stats/statter.go index 009ec38..dcecf67 100644 --- a/stats/statter.go +++ b/stats/statter.go @@ -5,12 +5,6 @@ import ( "time" ) -type key int - -const ( - ctxKey key = iota -) - var ( // Null is the null Statter instance. Null = &nullStatter{} @@ -50,7 +44,7 @@ func Timing(sable Statable, name string, value time.Duration, rate float32, tags sable.Statter().Timing(name, value, rate, tags...) } -// Close closes the client and flushes buffered stats, if applicable +// Close closes the client and flushes buffered stats, if applicable. func Close(sable Statable) error { return sable.Statter().Close() } diff --git a/timex/nanotime.go b/timex/nanotime.go deleted file mode 100644 index 16b1e1d..0000000 --- a/timex/nanotime.go +++ /dev/null @@ -1,27 +0,0 @@ -// Package timex implements extensions to the time package. -package timex - -import ( - "time" - _ "unsafe" // Required in order to import nanotime -) - -//go:linkname getNanotime runtime.nanotime -func getNanotime() int64 - -// Nanotime represents an instant in time with nanosecond precision using runtime.nanotime. -type Nanotime int64 - -// Now gets the current local time as a Nanotime. -// -// Deprecated: Use hamba/timex/mono instead. -func Now() Nanotime { - return Nanotime(getNanotime()) -} - -// Since returns the time elapsed since t. -// -// Deprecated: Use hamba/timex/mono instead. -func Since(t Nanotime) time.Duration { - return time.Duration(Now() - t) -} diff --git a/timex/nanotime.s b/timex/nanotime.s deleted file mode 100644 index e69de29..0000000 diff --git a/timex/nanotime_test.go b/timex/nanotime_test.go deleted file mode 100644 index 672f6b8..0000000 --- a/timex/nanotime_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package timex_test - -import ( - "testing" - "time" - - "github.com/hamba/pkg/timex" - "github.com/stretchr/testify/assert" -) - -func TestNanotime_Since(t *testing.T) { - then := timex.Nanotime(timex.Now() - 1000) - - d := timex.Since(then) - - assert.True(t, time.Duration(1000) <= d) -}