Skip to content

Commit

Permalink
Merge pull request #35 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.7.2
  • Loading branch information
andyone committed Mar 21, 2016
2 parents f41b12b + 38d5a72 commit 80e4ec9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: go

go:
- 1.4.3
- 1.5.3
- 1.6
- tip
Expand All @@ -16,7 +15,6 @@ env:
- EK_TEST_PORT=8080

before_install:
- go get -v golang.org/x/tools/cmd/cover
- go get -v pkg.re/check.v1

script:
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

#### v1.7.2

* `[errutil]` Added method Chain

#### v1.7.1

* `[log]` Improved min level changing
Expand Down
16 changes: 16 additions & 0 deletions errutil/errutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ func NewErrors() *Errors {
return &Errors{}
}

// Chain execute functions in chain and if one of them return error
// this function stop chain execution and return given error
func Chain(funcs ...func() error) error {
var err error

for _, fc := range funcs {
err = fc()

if err != nil {
return err
}
}

return err
}

// ////////////////////////////////////////////////////////////////////////////////// //

// Add adds new error to slice
Expand Down
17 changes: 17 additions & 0 deletions errutil/errutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,20 @@ func (s *ErrSuite) TestNegative(c *C) {
c.Assert(errs.HasErrors(), Equals, false)
c.Assert(errs.Last(), IsNil)
}

func (s *ErrSuite) TestChain(c *C) {
f1 := func() error {
return nil
}

f2 := func() error {
return errors.New("Error #2")
}

f3 := func() error {
return nil
}

c.Assert(Chain(f1, f2, f3), NotNil)
c.Assert(Chain(f1, f3), IsNil)
}

0 comments on commit 80e4ec9

Please sign in to comment.