Skip to content

Commit b950eeb

Browse files
authored
Merge pull request #59 from dyweb/errors/init
[errors] Replace pkg/errors Fix #54 - multi error and wrap error - multi error `Append(err error)` returns true if it got a non nil error uber-go/multierr#21 - `Wrap` would reuse stack if the underlying error has one pkg/errors#122, and if `Frames()` is not called, `runtime.Frames` would not be expanded to `[]runtime.Frame`
2 parents 7a8a931 + 9dd1c2c commit b950eeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1032
-100
lines changed

.ayi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
dep-install:
22
- dep ensure
33
test:
4-
- go test -v -cover ./cast/... ./config/... ./generator/... ./log/... ./requests/... ./structure/... ./util/...
4+
- go test -v -cover ./cast/... ./config/... ./errors/... ./generator/... ./log/... ./noodle/... ./requests/... ./structure/... ./util/...
55
scripts:
66
fmt:
7-
- gofmt -d -l -w ./cast ./config ./log ./requests ./structure ./util
7+
- gofmt -d -l -w ./cast ./config ./errors ./log ./requests ./structure ./util
88
- git status
99
check:
1010
# TODO: didn't see any error so far ...

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ install:
1313

1414
script:
1515
- make install
16-
- go test -v -cover ./cast/... ./config/... ./generator/... ./log/... ./noodle/... ./requests/... ./runner/... ./structure/... ./util/...
16+
- make test
17+
- make test-race
18+
- make vet
1719
# TODO: gommon doesn't have coverage ... amazing ..

Gopkg.lock

Lines changed: 4 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727

2828
ignored = [
2929
"github.com/dyweb/gommon/legacy",
30+
"github.com/dyweb/gommon/legacy/*",
3031
"github.com/dyweb/gommon/playground",
32+
"github.com/dyweb/gommon/playground/*",
3133
]
3234

33-
[[constraint]]
34-
name = "github.com/pkg/errors"
35-
version = "0.8.0"
36-
3735
[prune]
3836
go-tests = true
3937
unused-packages = true

Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1+
PKGS=./cast/... ./config/... ./errors/... ./generator/... ./log/... ./noodle/... ./requests/... ./structure/... ./util/...
2+
PKGST=./cast ./config ./errors ./generator ./log ./noodle ./requests ./structure ./util
3+
14
.PHONY: install
25
install:
36
go install ./cmd/gommon
47

58
.PHONY: test
69
test:
7-
go test -v -cover ./cast/... ./config/... ./generator/... ./log/... ./noodle/... ./requests/... ./structure/... ./util/...
10+
go test -v -cover $(PKGS)
11+
12+
.PHONY: test-race
13+
test-race:
14+
go test -race $(PKGS)
815

916
.PHONY: test-log
1017
test-log:
1118
go test -v -cover ./log/...
1219

1320
.PHONY: fmt
1421
fmt:
15-
gofmt -d -l -w ./cast ./config ./generator ./log ./noodle ./requests ./structure ./util
22+
gofmt -d -l -w $(PKGST)
23+
24+
.PHONY: vet
25+
vet:
26+
go vet $(PKGST)
27+
28+
.PHONy: doc
29+
doc:
30+
xdg-open http://localhost:6060/pkg/github.com/dyweb/gommon &
31+
godoc -http=":6060"
1632

1733
.PHONY: docker-test
1834
docker-test:

README.md

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ Gommon is a collection of common util libraries written in Go.
1010

1111
It has the following components:
1212

13-
- [Config](config) A YAML config reader with template support
14-
- [Log](log) A Javaish logger for Go, application can control library and set level for different pkg via config or flag
15-
- [Generator](generator) Render go template, generate methods for logger interface based on `gommon.yml`
16-
- [Noodle](noodle) Embed static assets for web application with `.noodleignore` support
17-
- [Requests](requests) A pythonic wrapper for `net/http`, HTTP for Gopher.
18-
- [Cast](cast) Convert Golang types
19-
- [Data structure](structure) Bring Set etc. to Golang.
13+
- [config](config) A YAML config reader with template support
14+
- [errors](errors) Wrap error and multi error
15+
- [generator](generator) Render go template, generate methods for logger interface based on `gommon.yml`
16+
- [log](log) A Javaish logger for Go, application can control library and set level for different pkg via config or flag
17+
- [noodle](noodle) Embed static assets for web application with `.noodleignore` support
18+
- [requests](requests) A pythonic wrapper for `net/http`, HTTP for Gopher.
19+
- [cast](cast) Convert Golang types
20+
- [structure](structure) Bring data structure like Set etc. to Golang.
2021

2122
Legacy
2223

@@ -26,16 +27,18 @@ Legacy
2627

2728
## Dependencies
2829

29-
Currently we only have two non standard library dependencies, see [Gopkg.lock](Gopkg.lock),
30-
we might replace them with our own implementation in the future.
30+
Currently we only have one non standard library dependencies, see [Gopkg.lock](Gopkg.lock)
3131

32-
- [pkg/errors](https://github.com/pkg/errors) for including context in error
33-
- however it's still not very machine friendly, we are likely to opt it out in future version
3432
- [go-yaml/yaml](https://github.com/go-yaml/yaml) for read config written in YAML
3533
- we don't need most feature of YAML, and want to have access to the parser directly to report which line has incorrect semantic (after checking it in application).
3634
- might write one in [ANTLR](https://github.com/antlr/antlr4)
3735
- we also have a DSL work in progress [RCL: Reika Configuration Language](https://github.com/at15/reika/issues/49), which is like [HCL](https://github.com/hashicorp/hcl2)
3836

37+
Removed
38+
39+
- [pkg/errors](https://github.com/pkg/errors) for including context in error
40+
- removed in [#59](https://github.com/dyweb/gommon/pull/59)
41+
3942
<!-- no, we are using the standard flag package ... -->
4043
<!-- For command line util, we are using [spf13/cobra](https://github.com/spf13/cobra), it is more flexible than [ufrave/cli](https://github.com/urfave/cli) -->
4144

@@ -66,23 +69,46 @@ Currently, gommon is in a very violate state, please open issues after it become
6669
Gommon is inspired by the following awesome libraries, most gommon packages have much less features and a few improvements
6770
compared to packages it modeled after.
6871

72+
log
73+
6974
- [sirupsen/logrus](https://github.com/sirupsen/logrus) for structured logging
7075
- log v1 is entirely modeled after logrus, entry contains log information with methods like `Info`, `Infof`
7176
- [apex/log](https://github.com/apex/log) for log handlers
7277
- log v2's handler is inspired by apex/log, but we didn't use entry and chose to pass multiple parameters to explicitly state what a handler should handle
7378
- [uber-go/zap](https://github.com/uber-go/zap) for serialize log fields without using `fmt.Sprintf` and use `strconv` directly
7479
- we didn't go that extreme as Zap or ZeroLog for zero allocation, performance is not our goal for now
80+
81+
config
82+
7583
- [spf13/cast](https://github.com/spf13/cast) for cast, it is used by Viper
7684
- [spf13/viper](https://github.com/spf13/viper/) for config
7785
- looking up config via string key makes type system useless, so we always marshal entire config file to a single struct
7886
- it also makes refactor easier
87+
88+
requests
89+
7990
- [Requests](http://docs.python-requests.org/en/master/) for requests
91+
- [hashicorp/go-cleanhttp](https://github.com/hashicorp/go-cleanhttp) for using non default http transport and client
92+
93+
generator
94+
8095
- [benbjohnson/tmpl](https://github.com/benbjohnson/tmpl) for go template generator
8196
- first saw it in [influxdata/influxdb](https://github.com/influxdata/influxdb/blob/master/tsdb/engine/tsm1/encoding.gen.go.tmpl)
8297
- we put template data in `gommon.yml`, so we don't need to pass data as json via cli
83-
- [GeertJohan/go.rice](https://github.com/GeertJohan/go.rice) for ~~rice~~ noodle
98+
99+
noodle
100+
101+
- [GeertJohan/go.rice](https://github.com/GeertJohan/go.rice)
84102
- we implemented `.gitignore` like [feature](https://github.com/at15/go.rice/issues/1) but the upstream didn't respond for the [feature request #83](https://github.com/GeertJohan/go.rice/issues/83)
85103

104+
errors
105+
106+
- [pkg/errors](https://github.com/pkg/errors) it can not introduce breaking change, but `WithMessage` and `WithStack` is annoying
107+
- see [#54](https://github.com/dyweb/gommon/issues/54) and [errors/doc](errors/doc) about other error packages
108+
- https://github.com/pkg/errors/pull/122 for check existing stack before attach new one
109+
- [uber-go/multierr#21]( https://github.com/uber-go/multierr/issues/21) for return bool after append
110+
- [hashicorp/go-multierror](https://github.com/hashicorp/go-multierror) for `ErrorOrNil`
111+
86112
## About
87113

88114
It was part of [Ayi](https://github.com/dyweb/Ayi) and split out for wider use.

cast/cast.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package cast
22

33
import (
44
"encoding/json"
5-
"github.com/pkg/errors"
5+
6+
"github.com/dyweb/gommon/errors"
67
"gopkg.in/yaml.v2"
78
)
89

cast/doc.go

Lines changed: 0 additions & 3 deletions
This file was deleted.

cast/pkg.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
// Package cast convert types safely and drop incompatible types during conversion
2+
//
3+
// it is inspired by https://github.com/spf13/cast
14
package cast

cmd/gommon/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// gommon is the commandline util for generator
12
package main
23

34
import (

0 commit comments

Comments
 (0)