Skip to content

Commit

Permalink
add ck-return example, expand README a little more
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegt committed Sep 27, 2022
1 parent 8da7d04 commit b09b85c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
16 changes: 14 additions & 2 deletions README.md
@@ -1,7 +1,8 @@
# goadapt

Use the Ck/Return pattern from this package to replace the common `if
err != nil {return err}` boilerplate.
The Ck/Return pattern from this package can be used to replace the
common `if err != nil {return err}` boilerplate. See
examples/ck-return.go for usage.

- Allows shorter, more readable code.
- Provides more descriptive error messages.
Expand All @@ -12,3 +13,14 @@ err != nil {return err}` boilerplate.
Inspired in part by Dave Cheney's
[https://github.com/pkg/errors](https://github.com/pkg/errors) and Harri
Lainio's [https://github.com/lainio/err2](https://github.com/lainio/err2).

This package includes several other possibly-useful functions,
including Assert(), Debug(), and Pprint(). Docs are admittedly still
thin -- see ./examples here and [elsewhere on
github](https://github.com/search?q=github.com%2Fstevegt%2Fgoadapt+extension%3A.go&type=Code&ref=advsearch&l=&l=) for now.

## TODO

- add more doc comments
- add more examples
- integrate examples into test cases
19 changes: 19 additions & 0 deletions examples/ck-return.go
@@ -0,0 +1,19 @@
package main

import (
"os"

. "github.com/stevegt/goadapt"
)

func main() {
err := foo()
Pl(err)
}

func foo() (err error) {
defer Return(&err)
_, err = os.Open("notafile")
Ck(err)
return
}

0 comments on commit b09b85c

Please sign in to comment.