Skip to content

Commit aa8cd97

Browse files
authored
🔀 Merge pull request #201 from ccamel/use-local-golangci
use last available version of golang-ci
2 parents 4bc40d1 + b206e09 commit aa8cd97

File tree

13 files changed

+55
-21
lines changed

13 files changed

+55
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
vendor/
1717

18+
bin/
19+
1820
go-graphql-subscription-example
1921

2022
coverage.txt

.go-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ linters:
1717
enable-all: true
1818
disable:
1919
- lll
20+
- gomnd
2021
fast: false
2122

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ install-tools:
1111
echo "installing esc..."; \
1212
go get -u github.com/mjibson/esc; \
1313
fi
14-
@if [ ! -f $(GOPATH)/bin/golangci-lint ]; then \
14+
@if [ ! -f ./bin/golangci-lint ]; then \
1515
echo "installing golangci-lint..."; \
16-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.18.0; \
16+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.27.0; \
1717
fi
1818
@if [ ! -f $(GOPATH)/bin/gothanks ]; then \
1919
echo "installing gothanks..."; \
@@ -27,7 +27,7 @@ gen-static: install-tools
2727
go generate main.go
2828

2929
check: install-tools
30-
golangci-lint run ./...
30+
./bin/golangci-lint run ./...
3131

3232
thanks: install-tools
3333
$(GOPATH)/bin/gothanks -y | grep -v "is already"

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/ccamel/go-graphql-subscription-example
22

3-
go 1.12
3+
go 1.14
44

55
require (
66
github.com/antonmedv/expr v1.8.8
@@ -14,6 +14,5 @@ require (
1414
github.com/segmentio/kafka-go v0.3.6
1515
github.com/spf13/cobra v1.0.0
1616
github.com/stretchr/objx v0.2.0 // indirect
17-
golang.org/x/net v0.0.0-20191011234655-491137f69257 // indirect
18-
golang.org/x/tools v0.0.0-20191124021906-f5828fc9a103 // indirect
17+
golang.org/x/tools v0.0.0-20200526224456-8b020aee10d2 // indirect
1918
)

go.sum

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0=
204204
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
205205
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
206206
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
207+
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
207208
github.com/zenazn/goji v0.9.0 h1:RSQQAbXGArQ0dIDEq+PI6WqN6if+5KHu6x2Cx/GXLTQ=
208209
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
209210
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
@@ -215,8 +216,11 @@ golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnf
215216
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
216217
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 h1:rlLehGeYg6jfoyz/eDqDU1iRXLKfR42nnNh57ytKEWo=
217218
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
219+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
220+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
218221
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
219222
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
223+
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
220224
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
221225
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
222226
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -226,8 +230,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
226230
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
227231
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
228232
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
229-
golang.org/x/net v0.0.0-20191011234655-491137f69257 h1:ry8e2D+cwaV6hk7lb3aRTjjZo24shrbK0e11QEOkTIg=
230-
golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
233+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
234+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
231235
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
232236
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
233237
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -264,9 +268,13 @@ golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db h1:9hRk1xeL9LTT3yX/941DqeB
264268
golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
265269
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74 h1:4cFkmztxtMslUX2SctSl+blCyXfpzhGOy9LhKAqSMA4=
266270
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
267-
golang.org/x/tools v0.0.0-20191124021906-f5828fc9a103 h1:etSZZCMgaL7Z8Zy3W70DnOZ9RNPujuF/2ueQnnM+Uoc=
268-
golang.org/x/tools v0.0.0-20191124021906-f5828fc9a103/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
271+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
272+
golang.org/x/tools v0.0.0-20200526224456-8b020aee10d2 h1:21BqcH/onxtGHn1A2GDOJjZnbt4Nlez629S3eaR+eYs=
273+
golang.org/x/tools v0.0.0-20200526224456-8b020aee10d2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
269274
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
275+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
276+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
277+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
270278
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
271279
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
272280
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=

server/kafka_consumer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package server
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"io"
89
"net/url"
@@ -15,6 +16,10 @@ import (
1516
"github.com/segmentio/kafka-go"
1617
)
1718

19+
var (
20+
ErrNoBrokerSpecified = errors.New("no broker specified")
21+
)
22+
1823
type kafkaSource struct {
1924
uri *url.URL
2025
brokers []string
@@ -68,7 +73,7 @@ func parseKafkaBrokers(source *url.URL) ([]string, error) {
6873
brokersStr := source.Query().Get("brokers")
6974

7075
if brokersStr == "" {
71-
return nil, fmt.Errorf("no brokers specified")
76+
return nil, fmt.Errorf("incorrect source URL %s: %w", source.String(), ErrNoBrokerSpecified)
7277
}
7378

7479
return strings.Split(brokersStr, ","), nil

server/resolver.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package server
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/url"
78

@@ -11,6 +12,11 @@ import (
1112
"github.com/ccamel/go-graphql-subscription-example/server/scalar"
1213
)
1314

15+
var (
16+
ErrUnknownTopic = errors.New("unknown topic")
17+
ErrUnmarshall = errors.New("unmarshall error")
18+
)
19+
1420
type Resolver struct {
1521
log zerolog.Logger
1622
cfg *Configuration
@@ -49,7 +55,7 @@ func (r *Resolver) Event(
4955
Matching *string
5056
}) (<-chan *scalar.JSONObject, error) {
5157
if !acceptTopic(args.On, r.cfg.Topics) {
52-
return nil, fmt.Errorf("unknown topic: '%s'. Valid topics are: %v", args.On, r.cfg.Topics)
58+
return nil, fmt.Errorf("incorrect topic '%s' (valid topics are: %v): %w", args.On, r.cfg.Topics, ErrUnknownTopic)
5359
}
5460

5561
c := make(chan *scalar.JSONObject)
@@ -108,7 +114,7 @@ func (r *Resolver) acceptMessage(m map[string]interface{}, predicate *string) bo
108114
r.log.
109115
Warn().
110116
Object("message", MapAsZerologObject(m)).
111-
Err(fmt.Errorf("incorrect type: %t returned. Expected boolean", out)).
117+
Err(fmt.Errorf("incorrect type %t returned - expected boolean: %w", out, ErrUnmarshall)).
112118
Msg("⚱️ Failed to filter (message will be dropped)")
113119

114120
return false

server/scalar/error.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package scalar
2+
3+
import "errors"
4+
5+
var (
6+
ErrUnmarshall = errors.New("unmarshall error")
7+
)

server/scalar/json.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ func (JSONObject) ImplementsGraphQLType(name string) bool {
2323
// UnmarshalGraphQL is a custom unmarshaler for JSONObject
2424
//
2525
// This function will be called whenever you use the
26-
// JSONObject scalar as an input
26+
// JSONObject scalar as an input.
2727
func (t *JSONObject) UnmarshalGraphQL(input interface{}) error {
2828
switch input := input.(type) {
2929
case map[string]interface{}:
3030
t.v = input
3131
return nil
3232
default:
33-
return fmt.Errorf("wrong type")
33+
return fmt.Errorf("type %T: %w", input, ErrUnmarshall)
3434
}
3535
}
3636

3737
// MarshalJSON is a custom marshaler for JSONObject
3838
//
3939
// This function will be called whenever you
40-
// query for fields that use the JSONObject type
40+
// query for fields that use the JSONObject type.
4141
func (t JSONObject) MarshalJSON() ([]byte, error) {
4242
return json.Marshal(t.v)
4343
}

server/scalar/offset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (t *Offset) UnmarshalGraphQL(input interface{}) error {
3636
t.v = v
3737

3838
if !success {
39-
return fmt.Errorf("error converting: %s", input)
39+
return fmt.Errorf("conversion of %s: %w", input, ErrUnmarshall)
4040
}
4141

4242
return nil
@@ -47,7 +47,7 @@ func (t *Offset) UnmarshalGraphQL(input interface{}) error {
4747
t.v = new(big.Int).SetUint64(v.Uint())
4848
return nil
4949
default:
50-
return fmt.Errorf("wrong type")
50+
return fmt.Errorf("type %T: %w", input, ErrUnmarshall)
5151
}
5252
}
5353

server/server.go

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

33
import (
4+
"errors"
45
"fmt"
56
"html/template"
67
"net/http"
@@ -49,7 +50,7 @@ func (s *Server) Start() {
4950
Uint16("port", s.cfg.Port).
5051
Msg("Ready to handle requests")
5152

52-
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
53+
if err := server.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) {
5354
s.log.
5455
Error().
5556
Err(err).

server/source.go

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

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/url"
78
"strings"
89

910
"github.com/reactivex/rxgo/v2"
1011
)
1112

13+
var (
14+
ErrIncorrectScheme = errors.New("incorrect scheme")
15+
)
16+
1217
// Source specifies types which are able to provide a source of events through an Observable.
1318
type Source interface {
1419
URI() *url.URL
@@ -45,5 +50,6 @@ func NewSource(uri *url.URL) (Source, error) {
4550
i++
4651
}
4752

48-
return nil, fmt.Errorf("scheme %s is not supported. Available are: ", strings.Join(keys, ","))
53+
return nil, fmt.Errorf("scheme %s is not supported (available are: %s): %w",
54+
uri.Scheme, strings.Join(keys, ","), ErrIncorrectScheme)
4955
}

0 commit comments

Comments
 (0)