Skip to content

Commit 4ac64a5

Browse files
authored
Merge pull request #2 from avast/readme_generator
Readme generator
2 parents 370b1f8 + 6fe0bd5 commit 4ac64a5

12 files changed

+359
-97
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@
1212

1313
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
1414
.glide/
15+
16+
# dep
17+
vendor/
18+
Gopkg.lock
19+
20+
# cover
21+
coverage.txt

.godocdown.tmpl

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# {{ .Name }}
2+
3+
[![Release](https://img.shields.io/github/release/avast/retry-go.svg?style=flat-square)](https://github.com/avast/retry-go/releases/latest)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
5+
[![Travis](https://img.shields.io/travis/avast/retry-go.svg?style=flat-square)](https://travis-ci.org/avast/retry-go)
6+
[![AppVeyor](https://ci.appveyor.com/api/projects/status/fieg9gon3qlq0a9a?svg=true)](https://ci.appveyor.com/project/JaSei/retry-go)
7+
[![Go Report Card](https://goreportcard.com/badge/github.com/avast/retry-go?style=flat-square)](https://goreportcard.com/report/github.com/avast/retry-go)
8+
[![GoDoc](https://godoc.org/github.com/avast/retry-go?status.svg&style=flat-square)](http://godoc.org/github.com/avast/retry-go)
9+
[![codecov.io](https://codecov.io/github/avast/retry-go/coverage.svg?branch=master)](https://codecov.io/github/avast/retry-go?branch=master)
10+
[![Sourcegraph](https://sourcegraph.com/github.com/avast/retry-go/-/badge.svg)](https://sourcegraph.com/github.com/avast/retry-go?badge)
11+
12+
{{ .EmitSynopsis }}
13+
14+
{{ .EmitUsage }}
15+
16+
## Contributing
17+
18+
Contributions are very much welcome.
19+
20+
### Makefile
21+
22+
Makefile provides several handy rules, like README.md `generator` , `setup` for prepare build/dev environment, `test`, `cover`, etc...
23+
24+
Try `make help` for more information.
25+
26+
### Before pull request
27+
28+
please try:
29+
* run tests (`make test`)
30+
* run linter (`make lint`)
31+
* if your IDE don't automaticaly do `go fmt`, run `go fmt` (`make fmt`)
32+
33+
### README
34+
35+
README.md are generate from template [.godocdown.tmpl](.godocdown.tmpl) and code documentation via [godocdown](https://github.com/robertkrimen/godocdown).
36+
37+
Never edit README.md direct, because your change will be lost.

.travis.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
language: go
22

33
go:
4-
- 1.2
5-
# - 1.3
6-
- 1.4
7-
- 1.5
84
- 1.6
95
- 1.7
10-
- tip
6+
- 1.8
7+
- 1.9
118

129
install:
13-
- go get -t -v -d ./...
10+
- make setup
1411

1512
script:
16-
- ./test.sh
13+
- make ci
1714

1815
after_success:
1916
- bash <(curl -s https://codecov.io/bash)

Gopkg.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[constraint]]
2+
name = "github.com/stretchr/testify"
3+
version = "1.1.4"

Makefile

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
SOURCE_FILES?=$$(go list ./... | grep -v /vendor/)
2+
TEST_PATTERN?=.
3+
TEST_OPTIONS?=
4+
DEP?=$$(which dep)
5+
6+
ifeq ($(OS),Windows_NT)
7+
DEP_VERS=dep-windows-amd64
8+
else
9+
DEP_VERS=dep-linux-amd64
10+
endif
11+
12+
setup: ## Install all the build and lint dependencies
13+
# fix of gopkg.in issue (https://github.com/niemeyer/gopkg/issues/50)
14+
git config --global http.https://gopkg.in.followRedirects true
15+
go get -u gopkg.in/alecthomas/gometalinter.v1
16+
go get -u github.com/pierrre/gotestcover
17+
go get -u golang.org/x/tools/cmd/cover
18+
go get -u github.com/robertkrimen/godocdown/godocdown
19+
gometalinter.v1 --install
20+
@if [ "$(DEP)" = "" ]; then\
21+
curl -L https://github.com/golang/dep/releases/download/v0.3.1/$(DEP_VERS) >| $$GOPATH/bin/dep;\
22+
chmod +x $$GOPATH/bin/dep;\
23+
fi
24+
dep ensure
25+
26+
generate: ## Generate README.md
27+
godocdown >| README.md
28+
29+
test: generate ## Run all the tests
30+
gotestcover $(TEST_OPTIONS) -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=2m
31+
32+
cover: test ## Run all the tests and opens the coverage report
33+
go tool cover -html=coverage.txt
34+
35+
fmt: ## gofmt and goimports all go files
36+
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done
37+
38+
lint: ## Run all the linters
39+
gometalinter.v1 --vendor --disable-all \
40+
--enable=deadcode \
41+
--enable=ineffassign \
42+
--enable=gosimple \
43+
--enable=staticcheck \
44+
--enable=gofmt \
45+
--enable=goimports \
46+
--enable=dupl \
47+
--enable=misspell \
48+
--enable=errcheck \
49+
--enable=vet \
50+
--deadline=10m \
51+
./...
52+
53+
ci: test lint ## Run all the tests and code checks
54+
55+
build:
56+
go build
57+
58+
# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
59+
help:
60+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
61+
62+
.DEFAULT_GOAL := build

README.md

+158-35
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,183 @@
11
# retry
22

3-
[![Linux Build Status](https://travis-ci.org/avast/retry-go.svg)](https://travis-ci.org/avast/retry-go)
4-
[![Windows Build status](https://ci.appveyor.com/api/projects/status/fieg9gon3qlq0a9a?svg=true)](https://ci.appveyor.com/project/JaSei/retry-go)
5-
[![Go Report Card](https://goreportcard.com/badge/github.com/avast/retry-go)](https://goreportcard.com/report/github.com/avast/retry-go)
6-
[![GoDoc](https://godoc.org/github.com/avast/retry-go?status.svg)](http://godoc.org/github.com/avast/retry-go)
3+
[![Release](https://img.shields.io/github/release/avast/retry-go.svg?style=flat-square)](https://github.com/avast/retry-go/releases/latest)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
5+
[![Travis](https://img.shields.io/travis/avast/retry-go.svg?style=flat-square)](https://travis-ci.org/avast/retry-go)
6+
[![AppVeyor](https://ci.appveyor.com/api/projects/status/fieg9gon3qlq0a9a?svg=true)](https://ci.appveyor.com/project/JaSei/retry-go)
7+
[![Go Report Card](https://goreportcard.com/badge/github.com/avast/retry-go?style=flat-square)](https://goreportcard.com/report/github.com/avast/retry-go)
8+
[![GoDoc](https://godoc.org/github.com/avast/retry-go?status.svg&style=flat-square)](http://godoc.org/github.com/avast/retry-go)
9+
[![codecov.io](https://codecov.io/github/avast/retry-go/coverage.svg?branch=master)](https://codecov.io/github/avast/retry-go?branch=master)
710
[![Sourcegraph](https://sourcegraph.com/github.com/avast/retry-go/-/badge.svg)](https://sourcegraph.com/github.com/avast/retry-go?badge)
8-
[![codecov.io](https://codecov.io/github/boennemann/badges/coverage.svg?branch=master)](https://codecov.io/github/avast/retry-go?branch=master)
911

1012
Simple library for retry mechanism
1113

12-
slightly inspired by [Try::Tiny::Retry](https://metacpan.org/pod/Try::Tiny::Retry)
14+
slightly inspired by
15+
[Try::Tiny::Retry](https://metacpan.org/pod/Try::Tiny::Retry)
1316

14-
## INSTALL && USE
1517

16-
To get the package, execute:
18+
### SYNOPSIS
1719

20+
http get with retry:
21+
22+
url := "http://example.com"
23+
var body []byte
24+
25+
err := retry.Retry(
26+
func() error {
27+
resp, err := http.Get(url)
28+
if err != nil {
29+
return err
30+
}
31+
defer resp.Body.Close()
32+
body, err = ioutil.ReadAll(resp.Body)
33+
if err != nil {
34+
return err
35+
}
36+
37+
return nil
38+
},
39+
)
40+
41+
fmt.Println(body)
42+
43+
[next examples](https://github.com/avast/retry-go/examples)
44+
45+
46+
### SEE ALSO
47+
48+
* [giantswarm/retry-go](https://github.com/giantswarm/retry-go) - slightly
49+
complicated interface.
50+
51+
* [sethgrid/pester](https://github.com/sethgrid/pester) - only http retry for
52+
http calls with retries and backoff
53+
54+
* [cenkalti/backoff](https://github.com/cenkalti/backoff) - Go port of the
55+
exponential backoff algorithm from Google's HTTP Client Library for Java. Really
56+
complicated interface.
57+
58+
## Usage
59+
60+
#### func Retry
61+
62+
```go
63+
func Retry(retryableFunction Retryable) error
64+
```
65+
Retry - simple retry
66+
67+
#### func RetryCustom
68+
69+
```go
70+
func RetryCustom(retryableFunction Retryable, onRetryFunction OnRetry, opts RetryOpts) error
1871
```
19-
go get gopkg.in/avast/retry-go.v0
72+
RetryCustom - the most customizable retry is possible set OnRetry function
73+
callback which are called each retry
74+
75+
#### func RetryWithOpts
76+
77+
```go
78+
func RetryWithOpts(retryableFunction Retryable, opts RetryOpts) error
2079
```
80+
RetryWithOpts - customizable retry via RetryOpts
2181

22-
To import this package, add the following line to your code:
82+
#### type Error
2383

2484
```go
25-
import "gopkg.in/avast/retry-go.v0"
85+
type Error []error
2686
```
2787

28-
### EXAMPLE
88+
Error type represents list of errors in retry
2989

30-
http get with retry:
90+
#### func (Error) Error
3191

3292
```go
33-
url := "http://example.com"
34-
var body []byte
93+
func (e Error) Error() string
94+
```
95+
Error method return string representation of Error It is an implementation of
96+
error interface
3597

36-
err := retry.Retry(
37-
func() error {
38-
resp, err := http.Get(url)
39-
if err != nil {
40-
return err
41-
}
42-
defer resp.Body.Close()
43-
body, err = ioutil.ReadAll(resp.Body)
44-
if err != nil {
45-
return err
46-
}
98+
#### func (Error) WrappedErrors
4799

48-
return nil
49-
},
50-
)
100+
```go
101+
func (e Error) WrappedErrors() []error
102+
```
103+
WrappedErrors returns the list of errors that this Error is wrapping. It is an
104+
implementation of the errwrap.Wrapper interface so that multierror.Error can be
105+
used with that library.
51106

52-
fmt.Println(body)
107+
#### type OnRetry
108+
109+
```go
110+
type OnRetry func(n uint, err error)
53111
```
54112

55-
[next examples](examples)
113+
Function signature of OnRetry function n = count of tries
114+
115+
#### type RetryOpts
116+
117+
```go
118+
type RetryOpts struct {
119+
}
120+
```
121+
122+
Struct for configure retry tries - count of tries delay - waiting time units -
123+
waiting time unit (for tests purpose)
124+
125+
#### func NewRetryOpts
126+
127+
```go
128+
func NewRetryOpts() RetryOpts
129+
```
130+
Create new RetryOpts struct with default values default tries are 10 default
131+
delay are 1e5 default units are microsecond
132+
133+
#### func (RetryOpts) Delay
134+
135+
```go
136+
func (opts RetryOpts) Delay(delay time.Duration) RetryOpts
137+
```
138+
Delay setter
139+
140+
#### func (RetryOpts) Tries
141+
142+
```go
143+
func (opts RetryOpts) Tries(tries uint) RetryOpts
144+
```
145+
Tries setter
146+
147+
#### func (RetryOpts) Units
148+
149+
```go
150+
func (opts RetryOpts) Units(timeUnit time.Duration) RetryOpts
151+
```
152+
Units setter
153+
154+
#### type Retryable
155+
156+
```go
157+
type Retryable func() error
158+
```
159+
160+
Function signature of retryable function
161+
162+
## Contributing
163+
164+
Contributions are very much welcome.
165+
166+
### Makefile
167+
168+
Makefile provides several handy rules, like README.md `generator` , `setup` for prepare build/dev environment, `test`, `cover`, etc...
169+
170+
Try `make help` for more information.
171+
172+
### Before pull request
173+
174+
please try:
175+
* run tests (`make test`)
176+
* run linter (`make lint`)
177+
* if your IDE don't automaticaly do `go fmt`, run `go fmt` (`make fmt`)
178+
179+
### README
180+
181+
README.md are generate from template [.godocdown.tmpl](.godocdown.tmpl) and code documentation via [godocdown](https://github.com/robertkrimen/godocdown).
56182

57-
## SEE ALSO
58-
* [giantswarm/retry-go](https://github.com/giantswarm/retry-go) - slightly complicated interface.
59-
* [sethgrid/pester](https://github.com/sethgrid/pester) - only http retry for http calls with retries and backoff
60-
* [cenkalti/backoff](https://github.com/cenkalti/backoff) - Go port of the exponential backoff algorithm from Google's HTTP Client Library for Java. Really complicated interface.
183+
Never edit README.md direct, because your change will be lost.

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.3.0

appveyor.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
version: "{build}"
22

3-
clone_folder: c:\go\src\github.com\avast\retry-go
3+
clone_folder: c:\Users\appveyor\go\src\github.com\avast\retry-go
44

55
#os: Windows Server 2012 R2
66
platform: x64
77

88
install:
9+
- copy c:\MinGW\bin\mingw32-make.exe c:\MinGW\bin\make.exe
10+
- set GOPATH=C:\Users\appveyor\go
11+
- set PATH=%PATH%;c:\MinGW\bin
12+
- set PATH=%PATH%;%GOPATH%\bin;c:\go\bin
13+
- set GOBIN=%GOPATH%\bin
914
- go version
1015
- go env
11-
- go get -v -t
16+
- make setup
1217

1318
build_script:
14-
- go test -v ./...
19+
- make ci

0 commit comments

Comments
 (0)