Skip to content

Commit 0f199af

Browse files
committed
move examples and experimentals to submodules
1 parent e372cc3 commit 0f199af

14 files changed

+63
-33
lines changed

docs.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Package retry provides the most advanced interruptible mechanism
2+
// to perform actions repetitively until successful.
3+
//
4+
// The retry based on https://github.com/Rican7/retry but fully reworked
5+
// and focused on integration with the https://github.com/kamilsk/breaker
6+
// and the built-in https://pkg.go.dev/context package.
7+
package retry

errors.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,7 @@ func (err Error) Error() string { return string(err) }
1111
// Unwrap always returns nil means that an error doesn't have other root cause.
1212
func (err Error) Unwrap() error { return nil }
1313

14-
// equal to go.octolab.org/errors.Unwrap
1514
func unwrap(err error) error {
16-
// compatible with github.com/pkg/errors
17-
type causer interface {
18-
Cause() error
19-
}
20-
// compatible with built-in errors since 1.13
21-
type wrapper interface {
22-
Unwrap() error
23-
}
24-
2515
for err != nil {
2616
layer, is := err.(wrapper)
2717
if is {
@@ -37,3 +27,13 @@ func unwrap(err error) error {
3727
}
3828
return err
3929
}
30+
31+
// compatible with github.com/pkg/errors
32+
type causer interface {
33+
Cause() error
34+
}
35+
36+
// compatible with built-in errors since 1.13
37+
type wrapper interface {
38+
Unwrap() error
39+
}

errors_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ func TestError(t *testing.T) {
1717
}
1818

1919
func TestUnwrap(t *testing.T) {
20-
cause := errors.New("root")
21-
core := unwrap(causer{layer{cause}})
22-
if !reflect.DeepEqual(core, cause) {
20+
root := errors.New("root")
21+
core := unwrap(cause{layer{root}})
22+
if !reflect.DeepEqual(core, root) {
2323
t.Error("unexpected behavior")
2424
}
2525
}
2626

2727
// helpers
2828

29-
type causer struct{ error }
29+
type cause struct{ error }
3030

31-
func (causer causer) Cause() error { return causer.error }
31+
func (cause cause) Cause() error { return cause.error }
3232

3333
type layer struct{ error }
3434

compare_test.go renamed to examples/compare_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package retry_test
1+
package examples_test
22

33
import (
44
"context"

examples/docs.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Package examples contains extended documentation
2+
// for github.com/kamilsk/retry/v5 module.
3+
//
4+
// It contains examples of usage with additional
5+
// dependencies that are not needed by the module.
6+
package examples

examples/go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/kamilsk/retry/examples
2+
3+
go 1.13
4+
5+
require github.com/kamilsk/retry/v5 v5.0.0-rc8
6+
7+
replace github.com/kamilsk/retry/v5 => ../

examples/http_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package examples_test

retry.go

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// Package retry provides the most advanced interruptible mechanism
2-
// to perform actions repetitively until successful.
3-
// The retry based on https://github.com/Rican7/retry but fully reworked
4-
// and focused on integration with the https://github.com/kamilsk/breaker
5-
// and the built-in https://pkg.go.dev/context package.
61
package retry
72

83
import (

sandbox/docs.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package exp contains experimental unstable
2+
// features.
3+
package sandbox

example_test.go renamed to sandbox/example_test.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
package retry_test
1+
// +build go1.13
2+
3+
package sandbox_test
24

35
import (
46
"context"
57
"database/sql"
8+
"errors"
69
"fmt"
710
"math/rand"
811
"net"
912
"time"
1013

14+
"github.com/kamilsk/retry/sandbox"
15+
1116
"github.com/kamilsk/retry/v5"
1217
"github.com/kamilsk/retry/v5/backoff"
13-
"github.com/kamilsk/retry/v5/exp"
1418
"github.com/kamilsk/retry/v5/jitter"
1519
"github.com/kamilsk/retry/v5/strategy"
1620
)
@@ -31,8 +35,8 @@ func Example() {
3135
),
3236

3337
// experimental
34-
exp.CheckError(
35-
exp.NetworkError(exp.Skip),
38+
sandbox.CheckError(
39+
sandbox.NetworkError(sandbox.Skip),
3640
DatabaseError(),
3741
),
3842
}
@@ -60,10 +64,10 @@ func SendRequest(ctx context.Context) error {
6064
}
6165

6266
func DatabaseError() func(error) bool {
63-
blacklist := []error{sql.ErrNoRows, sql.ErrConnDone, sql.ErrTxDone}
67+
deprecated := []error{sql.ErrNoRows, sql.ErrConnDone, sql.ErrTxDone}
6468
return func(err error) bool {
65-
for _, preset := range blacklist {
66-
if err == preset {
69+
for _, deprecated := range deprecated {
70+
if errors.Is(err, deprecated) {
6771
return false
6872
}
6973
}

sandbox/go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/kamilsk/retry/sandbox
2+
3+
go 1.11
4+
5+
require github.com/kamilsk/retry/v5 v5.0.0-rc8
6+
7+
replace github.com/kamilsk/retry/v5 => ../

exp/experimental.go renamed to sandbox/strategy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package exp
1+
package sandbox
22

33
import "net"
44

@@ -9,7 +9,7 @@ const (
99

1010
// A Breaker carries a cancellation signal to interrupt an action execution.
1111
//
12-
// It is a subset of the built-in Context and github.com/kamilsk/breaker interfaces.
12+
// It is a subset of the built-in context and github.com/kamilsk/breaker interfaces.
1313
type Breaker = interface {
1414
// Done returns a channel that's closed when a cancellation signal occurred.
1515
Done() <-chan struct{}

exp/experimental_test.go renamed to sandbox/strategy_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package exp_test
1+
package sandbox_test
22

33
import (
44
"context"
@@ -7,7 +7,7 @@ import (
77
"net"
88
"testing"
99

10-
. "github.com/kamilsk/retry/v5/exp"
10+
. "github.com/kamilsk/retry/sandbox"
1111
)
1212

1313
func TestCheckError(t *testing.T) {

strategy/strategy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "time"
55

66
// A Breaker carries a cancellation signal to interrupt an action execution.
77
//
8-
// It is a subset of the built-in Context and github.com/kamilsk/breaker interfaces.
8+
// It is a subset of the built-in context and github.com/kamilsk/breaker interfaces.
99
type Breaker = interface {
1010
// Done returns a channel that's closed when a cancellation signal occurred.
1111
Done() <-chan struct{}

0 commit comments

Comments
 (0)