Skip to content

Commit

Permalink
🔀 Merge pull request #201 from ccamel/use-local-golangci
Browse files Browse the repository at this point in the history
use last available version of golang-ci
  • Loading branch information
ccamel authored May 27, 2020
2 parents 4bc40d1 + b206e09 commit aa8cd97
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

vendor/

bin/

go-graphql-subscription-example

coverage.txt
1 change: 0 additions & 1 deletion .go-version

This file was deleted.

1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ linters:
enable-all: true
disable:
- lll
- gomnd
fast: false

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ install-tools:
echo "installing esc..."; \
go get -u github.com/mjibson/esc; \
fi
@if [ ! -f $(GOPATH)/bin/golangci-lint ]; then \
@if [ ! -f ./bin/golangci-lint ]; then \
echo "installing golangci-lint..."; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.18.0; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.27.0; \
fi
@if [ ! -f $(GOPATH)/bin/gothanks ]; then \
echo "installing gothanks..."; \
Expand All @@ -27,7 +27,7 @@ gen-static: install-tools
go generate main.go

check: install-tools
golangci-lint run ./...
./bin/golangci-lint run ./...

thanks: install-tools
$(GOPATH)/bin/gothanks -y | grep -v "is already"
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ccamel/go-graphql-subscription-example

go 1.12
go 1.14

require (
github.com/antonmedv/expr v1.8.8
Expand All @@ -14,6 +14,5 @@ require (
github.com/segmentio/kafka-go v0.3.6
github.com/spf13/cobra v1.0.0
github.com/stretchr/objx v0.2.0 // indirect
golang.org/x/net v0.0.0-20191011234655-491137f69257 // indirect
golang.org/x/tools v0.0.0-20191124021906-f5828fc9a103 // indirect
golang.org/x/tools v0.0.0-20200526224456-8b020aee10d2 // indirect
)
16 changes: 12 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0=
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zenazn/goji v0.9.0 h1:RSQQAbXGArQ0dIDEq+PI6WqN6if+5KHu6x2Cx/GXLTQ=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand All @@ -215,8 +216,11 @@ golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 h1:rlLehGeYg6jfoyz/eDqDU1iRXLKfR42nnNh57ytKEWo=
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -226,8 +230,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191011234655-491137f69257 h1:ry8e2D+cwaV6hk7lb3aRTjjZo24shrbK0e11QEOkTIg=
golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -264,9 +268,13 @@ golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db h1:9hRk1xeL9LTT3yX/941DqeB
golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74 h1:4cFkmztxtMslUX2SctSl+blCyXfpzhGOy9LhKAqSMA4=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191124021906-f5828fc9a103 h1:etSZZCMgaL7Z8Zy3W70DnOZ9RNPujuF/2ueQnnM+Uoc=
golang.org/x/tools v0.0.0-20191124021906-f5828fc9a103/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200526224456-8b020aee10d2 h1:21BqcH/onxtGHn1A2GDOJjZnbt4Nlez629S3eaR+eYs=
golang.org/x/tools v0.0.0-20200526224456-8b020aee10d2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down
7 changes: 6 additions & 1 deletion server/kafka_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/url"
Expand All @@ -15,6 +16,10 @@ import (
"github.com/segmentio/kafka-go"
)

var (
ErrNoBrokerSpecified = errors.New("no broker specified")
)

type kafkaSource struct {
uri *url.URL
brokers []string
Expand Down Expand Up @@ -68,7 +73,7 @@ func parseKafkaBrokers(source *url.URL) ([]string, error) {
brokersStr := source.Query().Get("brokers")

if brokersStr == "" {
return nil, fmt.Errorf("no brokers specified")
return nil, fmt.Errorf("incorrect source URL %s: %w", source.String(), ErrNoBrokerSpecified)
}

return strings.Split(brokersStr, ","), nil
Expand Down
10 changes: 8 additions & 2 deletions server/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"errors"
"fmt"
"net/url"

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

var (
ErrUnknownTopic = errors.New("unknown topic")
ErrUnmarshall = errors.New("unmarshall error")
)

type Resolver struct {
log zerolog.Logger
cfg *Configuration
Expand Down Expand Up @@ -49,7 +55,7 @@ func (r *Resolver) Event(
Matching *string
}) (<-chan *scalar.JSONObject, error) {
if !acceptTopic(args.On, r.cfg.Topics) {
return nil, fmt.Errorf("unknown topic: '%s'. Valid topics are: %v", args.On, r.cfg.Topics)
return nil, fmt.Errorf("incorrect topic '%s' (valid topics are: %v): %w", args.On, r.cfg.Topics, ErrUnknownTopic)
}

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

return false
Expand Down
7 changes: 7 additions & 0 deletions server/scalar/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package scalar

import "errors"

var (
ErrUnmarshall = errors.New("unmarshall error")
)
6 changes: 3 additions & 3 deletions server/scalar/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ func (JSONObject) ImplementsGraphQLType(name string) bool {
// UnmarshalGraphQL is a custom unmarshaler for JSONObject
//
// This function will be called whenever you use the
// JSONObject scalar as an input
// JSONObject scalar as an input.
func (t *JSONObject) UnmarshalGraphQL(input interface{}) error {
switch input := input.(type) {
case map[string]interface{}:
t.v = input
return nil
default:
return fmt.Errorf("wrong type")
return fmt.Errorf("type %T: %w", input, ErrUnmarshall)
}
}

// MarshalJSON is a custom marshaler for JSONObject
//
// This function will be called whenever you
// query for fields that use the JSONObject type
// query for fields that use the JSONObject type.
func (t JSONObject) MarshalJSON() ([]byte, error) {
return json.Marshal(t.v)
}
4 changes: 2 additions & 2 deletions server/scalar/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (t *Offset) UnmarshalGraphQL(input interface{}) error {
t.v = v

if !success {
return fmt.Errorf("error converting: %s", input)
return fmt.Errorf("conversion of %s: %w", input, ErrUnmarshall)
}

return nil
Expand All @@ -47,7 +47,7 @@ func (t *Offset) UnmarshalGraphQL(input interface{}) error {
t.v = new(big.Int).SetUint64(v.Uint())
return nil
default:
return fmt.Errorf("wrong type")
return fmt.Errorf("type %T: %w", input, ErrUnmarshall)
}
}

Expand Down
3 changes: 2 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"errors"
"fmt"
"html/template"
"net/http"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (s *Server) Start() {
Uint16("port", s.cfg.Port).
Msg("Ready to handle requests")

if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
if err := server.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) {
s.log.
Error().
Err(err).
Expand Down
8 changes: 7 additions & 1 deletion server/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package server

import (
"context"
"errors"
"fmt"
"net/url"
"strings"

"github.com/reactivex/rxgo/v2"
)

var (
ErrIncorrectScheme = errors.New("incorrect scheme")
)

// Source specifies types which are able to provide a source of events through an Observable.
type Source interface {
URI() *url.URL
Expand Down Expand Up @@ -45,5 +50,6 @@ func NewSource(uri *url.URL) (Source, error) {
i++
}

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

0 comments on commit aa8cd97

Please sign in to comment.