From ebefac6f40c39ef416a1dee616852242d41c35ec Mon Sep 17 00:00:00 2001 From: Dmitry Ponomarev Date: Fri, 25 Feb 2022 18:37:51 +0100 Subject: [PATCH 1/3] adjust to go1.18 --- .github/workflows/commitlint.yml | 11 +++ .github/workflows/golangci-lint.yml | 19 +++++ .github/workflows/release.yml | 17 +++++ center.go | 8 +-- decoder/decoder.go | 6 +- decoder/decoder_test.go | 2 +- dummy/publisher.go | 2 +- encoder/encoder.go | 6 +- encoder/encoder_test.go | 2 +- errors.go | 38 ---------- go.mod | 51 ++++++++++--- go.sum | 99 +++++++++++++++++++++----- gochan/go.go | 8 +-- handlers.go | 2 +- internal/bytebuffer/buffers.go | 2 +- internal/logger/default_logger.go | 6 +- internal/logger/default_logger_test.go | 8 +-- internal/objecthash/objecthash.go | 2 +- interval/message.go | 8 +-- interval/options.go | 2 +- interval/subscriber.go | 4 +- interval/subscriber_test.go | 8 +-- kafka/message.go | 17 ++--- kafka/message_test.go | 18 ++++- kafka/options.go | 19 ++--- kafka/publisher.go | 4 +- kafka/record.go | 2 +- kafka/subscriber.go | 91 +++++++++++------------ kafka/subscriber_test.go | 2 +- mocks/publisher.go | 8 +-- mocks/receiver.go | 2 +- mocks/subscriber.go | 4 +- nats/publisher.go | 2 +- nats/subscriber.go | 4 +- natstream/options.go | 4 +- natstream/publisher.go | 2 +- pg/logger_std.go | 6 +- pg/subscriber.go | 6 +- publisher.go | 24 ++++--- publisher_test.go | 4 +- receiver.go | 4 +- receiver_func.go | 6 +- redis/message.go | 2 +- redis/options.go | 6 +- redis/options_test.go | 4 +- redis/publisher.go | 9 +-- redis/subscriber.go | 4 +- registry.go | 16 ++--- registry_test.go | 2 +- wrappers/concurrency/options.go | 2 +- wrappers/concurrency/receiver.go | 2 +- wrappers/once/bigcache/checker.go | 4 +- wrappers/once/checker.go | 4 +- wrappers/once/publisher.go | 2 +- wrappers/once/redis/checker.go | 11 +-- wrappers/once/redis/checker_test.go | 14 ++-- 56 files changed, 362 insertions(+), 260 deletions(-) create mode 100644 .github/workflows/commitlint.yml create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .github/workflows/release.yml delete mode 100644 errors.go diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 0000000..7c716e6 --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,11 @@ +name: Lint Commit Messages +on: [pull_request] + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: wagoid/commitlint-github-action@v4 \ No newline at end of file diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..0fca5b7 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,19 @@ +name: golangci-lint + +on: + push: + tags: + - v* + branches: + - master + - main + pull_request: + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..405472a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,17 @@ +name: Releases + +on: + push: + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ncipollo/release-action@v1 + with: + body: + Please refer to + [CHANGELOG.md](https://github.com/geniusrabbit/notificationcenter/blob/master/CHANGELOG.md) for details diff --git a/center.go b/center.go index a1ffb73..282bdfa 100644 --- a/center.go +++ b/center.go @@ -1,6 +1,6 @@ // -// @project geniusrabbit.com 2016 – 2017, 2019 - 2020 -// @author Dmitry Ponomarev 2016 – 2017, 2019 - 2020 +// @project geniusrabbit.com 2016 – 2017, 2019 - 2022 +// @author Dmitry Ponomarev 2016 – 2017, 2019 - 2022 // package notificationcenter @@ -32,12 +32,12 @@ func SubscriberByName(name string) Subscriber { // "notifications", nats.MustNewSubscriber(), // ) // ``` -func Register(params ...interface{}) error { +func Register(params ...any) error { return DefaultRegistry.Register(params...) } // Publish one or more messages to the pub-service -func Publish(ctx context.Context, name string, messages ...interface{}) error { +func Publish(ctx context.Context, name string, messages ...any) error { return DefaultRegistry.Publish(ctx, name, messages...) } diff --git a/decoder/decoder.go b/decoder/decoder.go index 7ecdcce..cd208bf 100644 --- a/decoder/decoder.go +++ b/decoder/decoder.go @@ -6,14 +6,14 @@ import ( ) // Decoder function type -type Decoder func(data []byte, msg interface{}) error +type Decoder func(data []byte, msg any) error // JSON decoder implementation -func JSON(data []byte, msg interface{}) error { +func JSON(data []byte, msg any) error { return json.Unmarshal(data, msg) } // XML decoder implementation -func XML(data []byte, msg interface{}) error { +func XML(data []byte, msg any) error { return xml.Unmarshal(data, msg) } diff --git a/decoder/decoder_test.go b/decoder/decoder_test.go index 5a715ff..ef2b87c 100644 --- a/decoder/decoder_test.go +++ b/decoder/decoder_test.go @@ -15,7 +15,7 @@ type testItem struct { func TestDecoding(t *testing.T) { tests := []struct { - target interface{} + target any data string dec Decoder }{ diff --git a/dummy/publisher.go b/dummy/publisher.go index 45b1823..ab721ee 100644 --- a/dummy/publisher.go +++ b/dummy/publisher.go @@ -9,7 +9,7 @@ import ( type Publisher struct{} // Publish messages for dummy space -func (pub Publisher) Publish(ctx context.Context, messages ...interface{}) error { +func (pub Publisher) Publish(ctx context.Context, messages ...any) error { for _, msg := range messages { log.Println("publish", msg) } diff --git a/encoder/encoder.go b/encoder/encoder.go index ff31299..edc29b3 100644 --- a/encoder/encoder.go +++ b/encoder/encoder.go @@ -7,17 +7,17 @@ import ( ) // Encoder function type -type Encoder func(msg interface{}, wr io.Writer) error +type Encoder func(msg any, wr io.Writer) error // JSON encoder implementation -func JSON(msg interface{}, wr io.Writer) error { +func JSON(msg any, wr io.Writer) error { enc := json.NewEncoder(wr) enc.SetEscapeHTML(false) return enc.Encode(msg) } // XML encoder implementation -func XML(msg interface{}, wr io.Writer) error { +func XML(msg any, wr io.Writer) error { enc := xml.NewEncoder(wr) return enc.Encode(msg) } diff --git a/encoder/encoder_test.go b/encoder/encoder_test.go index 52a4661..0f5b012 100644 --- a/encoder/encoder_test.go +++ b/encoder/encoder_test.go @@ -16,7 +16,7 @@ type testItem struct { func TestEncoding(t *testing.T) { tests := []struct { - obj interface{} + obj any target string enc Encoder }{ diff --git a/errors.go b/errors.go deleted file mode 100644 index c95331a..0000000 --- a/errors.go +++ /dev/null @@ -1,38 +0,0 @@ -package notificationcenter - -import "bytes" - -type multiError []error - -// MultiError data type -func MultiError(errors ...error) error { - return multiError(errors) -} - -func (e multiError) Error() string { - if len(e) == 0 { - return `` - } - var buff bytes.Buffer - for i, err := range e { - if i > 0 { - buff.WriteByte('\n') - } - buff.Write([]byte(`- `)) - buff.WriteString(err.Error()) - } - return buff.String() -} - -func (e *multiError) Add(err error) { - if e != nil && err != nil { - *e = append(*e, err) - } -} - -func (e multiError) AsError() error { - if len(e) == 0 { - return nil - } - return e -} diff --git a/go.mod b/go.mod index eadba93..25ae4ca 100644 --- a/go.mod +++ b/go.mod @@ -1,26 +1,55 @@ module github.com/geniusrabbit/notificationcenter -go 1.15 +go 1.18 require ( - github.com/Shopify/sarama v1.29.1 - github.com/alicebob/miniredis v2.5.0+incompatible + github.com/Shopify/sarama v1.32.0 github.com/alicebob/miniredis/v2 v2.15.1 github.com/allegro/bigcache v1.2.1 github.com/bsm/sarama-cluster v2.1.15+incompatible github.com/demdxx/gocast v1.0.1 github.com/demdxx/rpool v0.0.0-20200317152850-d737c64d8aaf - github.com/elliotchance/redismock v1.5.3 - github.com/go-redis/redis v6.15.9+incompatible + github.com/elliotchance/redismock/v8 v8.11.0 + github.com/go-redis/redis/v8 v8.11.4 github.com/golang/mock v1.6.0 - github.com/gomodule/redigo v2.0.0+incompatible // indirect github.com/lib/pq v1.10.2 - github.com/nats-io/nats-streaming-server v0.22.0 // indirect - github.com/nats-io/nats.go v1.11.0 - github.com/nats-io/stan.go v0.9.0 - github.com/onsi/ginkgo v1.16.4 // indirect + github.com/nats-io/nats.go v1.13.0 + github.com/nats-io/stan.go v0.10.2 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.7.0 - github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect go.uber.org/multierr v1.7.0 ) + +require ( + github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect + github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/eapache/go-resiliency v1.2.0 // indirect + github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect + github.com/eapache/queue v1.1.0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/hashicorp/go-uuid v1.0.2 // indirect + github.com/jcmturner/aescts/v2 v2.0.0 // indirect + github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect + github.com/jcmturner/gofork v1.0.0 // indirect + github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect + github.com/jcmturner/rpc/v2 v2.0.3 // indirect + github.com/klauspost/compress v1.14.4 // indirect + github.com/nats-io/nats-server/v2 v2.2.6 // indirect + github.com/nats-io/nats-streaming-server v0.22.0 // indirect + github.com/nats-io/nkeys v0.3.0 // indirect + github.com/nats-io/nuid v1.0.1 // indirect + github.com/onsi/ginkgo v1.16.5 // indirect + github.com/onsi/gomega v1.18.1 // indirect + github.com/pierrec/lz4 v2.6.1+incompatible // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect + github.com/stretchr/objx v0.1.0 // indirect + github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect + go.uber.org/atomic v1.7.0 // indirect + golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect + golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect +) diff --git a/go.sum b/go.sum index b2ab760..63828ec 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,15 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/Shopify/sarama v1.29.1 h1:wBAacXbYVLmWieEA/0X/JagDdCZ8NVFOfS6l6+2u5S0= github.com/Shopify/sarama v1.29.1/go.mod h1:mdtqvCSg8JOxk8PmpTNGyo6wzd4BMm4QXSfDnTXmgkE= +github.com/Shopify/sarama v1.32.0 h1:P+RUjEaRU0GMMbYexGMDyrMkLhbbBVUVISDywi+IlFU= +github.com/Shopify/sarama v1.32.0/go.mod h1:+EmJJKZWVT/faR9RcOxJerP+LId4iWdQPBGLy1Y1Njs= github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/Shopify/toxiproxy/v2 v2.3.0/go.mod h1:KvQTtB6RjCJY4zqNJn7C7JDFgsG5uoHYDirfUfpIm0c= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= -github.com/alicebob/miniredis v2.5.0+incompatible h1:yBHoLpsyjupjz3NL3MhKMVkR41j82Yjf3KFv7ApYzUI= -github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk= +github.com/alicebob/miniredis/v2 v2.14.1/go.mod h1:uS970Sw5Gs9/iK3yBg0l9Uj9s25wXxSpQUE9EaJ/Blg= github.com/alicebob/miniredis/v2 v2.15.1 h1:Fw+ixAJPmKhCLBqDwHlTDqxUxp0xjEwXczEpt1B6r7k= github.com/alicebob/miniredis/v2 v2.15.1/go.mod h1:gquAfGbzn92jvtrSC69+6zZnwSODVXVpYDRaGhWaL6I= github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= @@ -16,11 +19,15 @@ github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQh github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bsm/sarama-cluster v2.1.15+incompatible h1:RkV6WiNRnqEEbp81druK8zYhmnIgdOjqSVi0+9Cnl2A= github.com/bsm/sarama-cluster v2.1.15+incompatible/go.mod h1:r7ao+4tTNXvWm+VRpRJchr2kQhqxgmAp2iEX5W96gMM= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -29,26 +36,29 @@ github.com/demdxx/gocast v1.0.1 h1:5dIlibBCaaGD4SCBWNHyKUt3DNlbcIbtoJjMH1CNgRY= github.com/demdxx/gocast v1.0.1/go.mod h1:doeaWGKAe/UuiDhJ3tmbSK2RwN5qK+8Z18RRVzHLNsA= github.com/demdxx/rpool v0.0.0-20200317152850-d737c64d8aaf h1:qTk+vPwzCp/on8DpTLDizwwvo08DNlj0ptDYwP+R4ng= github.com/demdxx/rpool v0.0.0-20200317152850-d737c64d8aaf/go.mod h1:x9oXikUwI05ecNFxo0JUpQ6hABl2lNtKMXv2wlDduyk= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/eapache/go-resiliency v1.2.0 h1:v7g92e/KSN71Rq7vSThKaWIq68fL4YHvWyiUKorFR1Q= github.com/eapache/go-resiliency v1.2.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8/yCZMuEPMUDHG0CW/brkkEp8mzqk2+ODEitlw= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/elliotchance/redismock v1.5.3 h1:Lgi2CLfVB3PamPI1SPqjJf5AiGisPFMWvIOCiRIq+sI= -github.com/elliotchance/redismock v1.5.3/go.mod h1:8FFsGWghPUyP7nqj/UYXr2xqd6U2iNMxS4S5+Xadl5A= +github.com/elliotchance/redismock/v8 v8.11.0 h1:tIGID1CQx6uTI7O7eu/85OUzJuagAvP7MCQswHj6qRI= +github.com/elliotchance/redismock/v8 v8.11.0/go.mod h1:c4Rd6BBiowXI+1woEB26rw0Cqsq763W9yTTxCIryTDE= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= +github.com/frankban/quicktest v1.14.2/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= -github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-redis/redis/v8 v8.11.0/go.mod h1:DLomh7y2e3ggQXQLd1YgmvIfecPJoFl7WU5SOQ/r06M= +github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= +github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -61,20 +71,25 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= -github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= -github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= @@ -94,6 +109,7 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/raft v1.3.1 h1:zDT8ke8y2aP4wf9zPTB2uSIeavJ3Hx/ceY4jxI2JxuY= github.com/hashicorp/raft v1.3.1/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= @@ -111,8 +127,12 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.12.2 h1:2KCfW3I9M7nSc5wOqXAlW2v2U6v+w6cbjvbfp+OykW8= github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/klauspost/compress v1.14.4 h1:eijASRJcobkVtSt81Olfh7JX43osYLwy5krOJo6YEu4= +github.com/klauspost/compress v1.14.4/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -137,6 +157,8 @@ github.com/nats-io/nats-streaming-server v0.22.0 h1:2egnq86o9roTqUfELlqykf7ZZkNv github.com/nats-io/nats-streaming-server v0.22.0/go.mod h1:Jyu3eUQaUAjwd5TiBuLagKdQRofPrHoIXt1kL0U/e5o= github.com/nats-io/nats.go v1.11.0 h1:L263PZkrmkRJRJT2YHU8GwWWvEvmr9/LUKuJTXsF32k= github.com/nats-io/nats.go v1.11.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= +github.com/nats-io/nats.go v1.13.0 h1:LvYqRB5epIzZWQp6lmeltOOZNLqCvm4b+qfvzZO03HE= +github.com/nats-io/nats.go v1.13.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s= github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8= github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= @@ -144,20 +166,30 @@ github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nats-io/stan.go v0.9.0 h1:TB73Y31au++0sU0VmnBy2pYkSrwH0zUFNRB9YePHqC4= github.com/nats-io/stan.go v0.9.0/go.mod h1:0jEuBXKauB1HHJswHM/lx05K48TJ1Yxj6VIfM4k+aB4= +github.com/nats-io/stan.go v0.10.2 h1:gQLd05LhzmhFkHm3/qP/klYHfM/hys45GyHa1Uly/kI= +github.com/nats-io/stan.go v0.10.2/go.mod h1:vo2ax8K2IxaR3JtEMLZRFKIdoK/3o1/PKueapB7ezX0= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= +github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= +github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= +github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pierrec/lz4 v2.6.0+incompatible h1:Ix9yFKn1nSPBLFl/yZknTp8TU5G4Ps0JDmguYK6iH1A= github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= +github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -171,6 +203,10 @@ github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3x github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -181,11 +217,16 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.0/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= +github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/xdg/scram v1.0.3/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg/stringprep v1.0.3/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ= github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA= github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 h1:k/gmLsJDWwWqbLCur2yWnJzwQEKRcAHXo6seXGuSwWw= github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA= @@ -204,6 +245,8 @@ golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -216,10 +259,15 @@ golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q= golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= 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= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -236,7 +284,9 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -247,13 +297,17 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -273,18 +327,25 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/gochan/go.go b/gochan/go.go index 992a8bd..e78b44e 100644 --- a/gochan/go.go +++ b/gochan/go.go @@ -9,13 +9,13 @@ import ( nc "github.com/geniusrabbit/notificationcenter" ) -func jsonEncoder(msg interface{}, wr io.Writer) error { +func jsonEncoder(msg any, wr io.Writer) error { enc := json.NewEncoder(wr) enc.SetEscapeHTML(false) return enc.Encode(msg) } -type encoder func(msg interface{}, wr io.Writer) error +type encoder func(msg any, wr io.Writer) error // Publisher writer for GO proxy server type Publisher struct { @@ -23,7 +23,7 @@ type Publisher struct { } // Publish one or more messages to the pub-service -func (p Publisher) Publish(ctx context.Context, messages ...interface{}) error { +func (p Publisher) Publish(ctx context.Context, messages ...any) error { for _, msg := range messages { if err := p.proxy.write(ctx, msg); err != nil { return err @@ -55,7 +55,7 @@ func (p *Proxy) Publisher() Publisher { return Publisher{proxy: p} } -func (p *Proxy) write(ctx context.Context, msg interface{}) error { +func (p *Proxy) write(ctx context.Context, msg any) error { buff := &bytes.Buffer{} if err := p.encoder(msg, buff); err != nil { return err diff --git a/handlers.go b/handlers.go index 905a519..a5acb9b 100644 --- a/handlers.go +++ b/handlers.go @@ -4,4 +4,4 @@ package notificationcenter type ErrorHandler func(msg Message, err error) // PanicHandler type to process panic action -type PanicHandler func(msg Message, recoverData interface{}) +type PanicHandler func(msg Message, recoverData any) diff --git a/internal/bytebuffer/buffers.go b/internal/bytebuffer/buffers.go index 2ef50bf..eb6900d 100644 --- a/internal/bytebuffer/buffers.go +++ b/internal/bytebuffer/buffers.go @@ -5,7 +5,7 @@ import ( "sync" ) -var buffers = sync.Pool{New: func() interface{} { return &bytes.Buffer{} }} +var buffers = sync.Pool{New: func() any { return &bytes.Buffer{} }} // AcquireBuffer from the pool func AcquireBuffer() *bytes.Buffer { diff --git a/internal/logger/default_logger.go b/internal/logger/default_logger.go index 1344e1f..539b0aa 100644 --- a/internal/logger/default_logger.go +++ b/internal/logger/default_logger.go @@ -7,10 +7,10 @@ var DefaultLogger defaultLogger type defaultLogger struct{} -func (l defaultLogger) Error(params ...interface{}) { - log.Println(append([]interface{}{`[error]`}, params...)...) +func (l defaultLogger) Error(params ...any) { + log.Println(append([]any{`[error]`}, params...)...) } -func (l defaultLogger) Debugf(msg string, params ...interface{}) { +func (l defaultLogger) Debugf(msg string, params ...any) { log.Printf(`[debug] `+msg+`\n`, params...) } diff --git a/internal/logger/default_logger_test.go b/internal/logger/default_logger_test.go index 13395a8..354c7b8 100644 --- a/internal/logger/default_logger_test.go +++ b/internal/logger/default_logger_test.go @@ -7,14 +7,14 @@ import ( ) type targetInterface interface { - Error(params ...interface{}) - Debugf(msg string, params ...interface{}) + Error(params ...any) + Debugf(msg string, params ...any) } func TestDefaultLogger(t *testing.T) { var ( - def interface{} = DefaultLogger - lg, _ = def.(targetInterface) + def any = DefaultLogger + lg, _ = def.(targetInterface) ) assert.NotNil(t, lg) } diff --git a/internal/objecthash/objecthash.go b/internal/objecthash/objecthash.go index 0115765..8ff2870 100644 --- a/internal/objecthash/objecthash.go +++ b/internal/objecthash/objecthash.go @@ -10,7 +10,7 @@ type objectHash interface { } // Hash value from the object -func Hash(obj interface{}) string { +func Hash(obj any) string { if ohasher, ok := obj.(objectHash); ok { return ohasher.ObjectHash() } diff --git a/interval/message.go b/interval/message.go index 8267993..6d68b81 100644 --- a/interval/message.go +++ b/interval/message.go @@ -10,12 +10,12 @@ import ( var ErrInvalidMessageType = errors.New(`invalid message type`) type messageValue interface { - Value() interface{} + Value() any } type message struct { ctx context.Context - v interface{} + v any } // Context of the message @@ -47,12 +47,12 @@ func (m *message) Ack() error { } // Value returns value of the message -func (m *message) Value() interface{} { +func (m *message) Value() any { return m.v } // MessageValue take the target value from the message -func MessageValue(m interface{}) interface{} { +func MessageValue(m any) any { switch v := m.(type) { case messageValue: return v.Value() diff --git a/interval/options.go b/interval/options.go index 967c780..af28d0f 100644 --- a/interval/options.go +++ b/interval/options.go @@ -4,7 +4,7 @@ import ( nc "github.com/geniusrabbit/notificationcenter" ) -type handler func() interface{} +type handler func() any // Options time interval wrapper type Options struct { diff --git a/interval/subscriber.go b/interval/subscriber.go index d0ac694..28444d5 100644 --- a/interval/subscriber.go +++ b/interval/subscriber.go @@ -12,7 +12,7 @@ type interval struct { timeInterval time.Duration ticker *time.Ticker - msgFnk func() interface{} + msgFnk func() any } // NewSubscriber with interval message generation @@ -22,7 +22,7 @@ func NewSubscriber(timeInterval time.Duration, options ...Option) nc.Subscriber opt(&opts) } if opts.Handler == nil { - opts.Handler = func() interface{} { return struct{}{} } + opts.Handler = func() any { return struct{}{} } } return &interval{ ModelSubscriber: nc.ModelSubscriber{ diff --git a/interval/subscriber_test.go b/interval/subscriber_test.go index 27af241..334b0e8 100644 --- a/interval/subscriber_test.go +++ b/interval/subscriber_test.go @@ -18,7 +18,7 @@ func TestInterval(t *testing.T) { ) defer cancel() - sub := NewSubscriber(time.Millisecond, WithHandler(func() interface{} { return "test" })) + sub := NewSubscriber(time.Millisecond, WithHandler(func() any { return "test" })) err := sub.Subscribe(ctx, nc.FuncReceiver(func(msg nc.Message) error { switch v := MessageValue(msg).(type) { case string: @@ -44,8 +44,8 @@ func TestIntervalPanic(t *testing.T) { defer cancel() sub := NewSubscriber(time.Millisecond, - WithHandler(func() interface{} { return "test" }), - WithPanicHandler(func(msg nc.Message, recoverData interface{}) { + WithHandler(func() any { return "test" }), + WithPanicHandler(func(msg nc.Message, recoverData any) { assert.Equal(t, "test", recoverData) }), ) @@ -65,7 +65,7 @@ func TestIntervalError(t *testing.T) { defer cancel() sub := NewSubscriber(time.Millisecond, - WithHandler(func() interface{} { return "test" }), + WithHandler(func() any { return "test" }), WithErrorHandler(func(msg nc.Message, err error) { assert.Equal(t, testError, err) }), diff --git a/kafka/message.go b/kafka/message.go index 695d37c..ff9812a 100644 --- a/kafka/message.go +++ b/kafka/message.go @@ -2,24 +2,18 @@ package kafka import ( "context" - "errors" "github.com/Shopify/sarama" - cluster "github.com/bsm/sarama-cluster" ) -// ErrMessageInvalidConsumer error -var ErrMessageInvalidConsumer = errors.New(`[message] invalid consumer`) - type message struct { - ctx context.Context - msg *sarama.ConsumerMessage - consumer *cluster.Consumer + msg *sarama.ConsumerMessage + session sarama.ConsumerGroupSession } // Context of the message func (m *message) Context() context.Context { - return m.ctx + return m.session.Context() } // ID returns unical message ID (depends on transport) @@ -34,9 +28,6 @@ func (m *message) Body() []byte { // Acknowledgment of the message processing func (m *message) Ack() error { - if m.consumer == nil { - return ErrMessageInvalidConsumer - } - m.consumer.MarkOffset(m.msg, "") + m.session.MarkMessage(m.msg, "") return nil } diff --git a/kafka/message_test.go b/kafka/message_test.go index 1991716..f4aea2d 100644 --- a/kafka/message_test.go +++ b/kafka/message_test.go @@ -1,6 +1,7 @@ package kafka import ( + "context" "encoding/json" "math/rand" "sync" @@ -13,15 +14,26 @@ import ( "github.com/geniusrabbit/notificationcenter/internal/bytebuffer" ) +type testGroupSession struct{} + +func (*testGroupSession) Claims() map[string][]int32 { return nil } +func (*testGroupSession) MemberID() string { return "" } +func (*testGroupSession) GenerationID() int32 { return 0 } +func (*testGroupSession) MarkOffset(topic string, partition int32, offset int64, metadata string) {} +func (*testGroupSession) Commit() {} +func (*testGroupSession) ResetOffset(topic string, partition int32, offset int64, metadata string) {} +func (*testGroupSession) MarkMessage(msg *sarama.ConsumerMessage, metadata string) {} +func (*testGroupSession) Context() context.Context { return nil } + func TestMessage(t *testing.T) { msg := &message{ - msg: &sarama.ConsumerMessage{Value: []byte(`{"data": "test"}`)}, - consumer: nil, + msg: &sarama.ConsumerMessage{Value: []byte(`{"data": "test"}`)}, + session: &testGroupSession{}, } assert.Equal(t, []byte(`{"data": "test"}`), msg.Body()) assert.Equal(t, ``, msg.ID()) assert.Nil(t, msg.Context()) - assert.Error(t, msg.Ack()) + assert.Nil(t, msg.Ack()) } func TestAsyncEncode(t *testing.T) { diff --git a/kafka/options.go b/kafka/options.go index 6ccc06b..f8c79d3 100644 --- a/kafka/options.go +++ b/kafka/options.go @@ -7,7 +7,6 @@ import ( "time" "github.com/Shopify/sarama" - cluster "github.com/bsm/sarama-cluster" nc "github.com/geniusrabbit/notificationcenter" "github.com/geniusrabbit/notificationcenter/encoder" @@ -16,7 +15,7 @@ import ( // Options for publisher or subscriber type Options struct { - ClusterConfig cluster.Config + ClusterConfig sarama.Config // IsSynchronous type of producer // TODO: make it work for sync publisher @@ -53,12 +52,12 @@ type Options struct { Logger loggerInterface } -func (opt *Options) clusterConfig() *cluster.Config { +func (opt *Options) clusterConfig() *sarama.Config { return &opt.ClusterConfig } func (opt *Options) saramaConfig() *sarama.Config { - return &opt.ClusterConfig.Config + return &opt.ClusterConfig } func (opt *Options) encoder() encoder.Encoder { @@ -88,7 +87,7 @@ type Option func(options *Options) // WithSaramaConfig custom config func WithSaramaConfig(streamConfig *sarama.Config) Option { return func(options *Options) { - options.ClusterConfig.Config = *streamConfig + options.ClusterConfig = *streamConfig } } @@ -125,7 +124,7 @@ func WithKafkaURL(urlString string) Option { // WithClientID value func WithClientID(clientID string) Option { return func(options *Options) { - options.ClusterConfig.Config.ClientID = clientID + options.ClusterConfig.ClientID = clientID } } @@ -212,14 +211,6 @@ func WithPublisherSuccessHandler(h PublisherSuccessHandler) Option { // WithSubscriberNotificationHandler set handler of the cluster group notifications func WithSubscriberNotificationHandler(h SubscriberNotificationHandler) Option { return func(options *Options) { - options.ClusterConfig.Group.Return.Notifications = h != nil options.SubscriberNotificationHandler = h } } - -// WithClusterConfig custom config -func WithClusterConfig(clusterConfig *cluster.Config) Option { - return func(options *Options) { - options.ClusterConfig = *clusterConfig - } -} diff --git a/kafka/publisher.go b/kafka/publisher.go index ab715b5..291b1f8 100644 --- a/kafka/publisher.go +++ b/kafka/publisher.go @@ -53,7 +53,7 @@ type Publisher struct { // NewPublisher to the kafka with some brokers and topics for sending func NewPublisher(ctx context.Context, options ...Option) (*Publisher, error) { var opts Options - opts.ClusterConfig.Config = *sarama.NewConfig() + opts.ClusterConfig = *sarama.NewConfig() for _, opt := range options { opt(&opts) } @@ -90,7 +90,7 @@ func MustNewPublisher(ctx context.Context, options ...Option) *Publisher { /////////////////////////////////////////////////////////////////////////////// // Publish one or more messages to the pub-service -func (p *Publisher) Publish(ctx context.Context, messages ...interface{}) (err error) { +func (p *Publisher) Publish(ctx context.Context, messages ...any) (err error) { buff := bytebuffer.AcquireBuffer() defer func() { bytebuffer.ReleaseBuffer(buff) diff --git a/kafka/record.go b/kafka/record.go index c458e53..326a315 100644 --- a/kafka/record.go +++ b/kafka/record.go @@ -10,7 +10,7 @@ import "sync" const minimalMessageSize = 1000 var byteEncoderPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &kafkaByteEncoder{data: make([]byte, 0, minimalMessageSize)} }, } diff --git a/kafka/subscriber.go b/kafka/subscriber.go index 094309d..e24cee2 100644 --- a/kafka/subscriber.go +++ b/kafka/subscriber.go @@ -9,13 +9,14 @@ import ( "context" "time" + "github.com/Shopify/sarama" cluster "github.com/bsm/sarama-cluster" "github.com/geniusrabbit/notificationcenter" ) type loggerInterface interface { - Error(params ...interface{}) - Debugf(msg string, params ...interface{}) + Error(params ...any) + Debugf(msg string, params ...any) } // SubscriberNotificationHandler callback function @@ -25,8 +26,11 @@ type SubscriberNotificationHandler func(notification *cluster.Notification) type Subscriber struct { notificationcenter.ModelSubscriber + topics []string + // consumer object which receive the messages - consumer *cluster.Consumer + // consumer *cluster.Consumer + consumerGroup sarama.ConsumerGroup // notificationHandler callback notificationHandler SubscriberNotificationHandler @@ -38,12 +42,12 @@ type Subscriber struct { // NewSubscriber connection to kafka "group" from list of topics func NewSubscriber(options ...Option) (*Subscriber, error) { var opts Options - opts.ClusterConfig = *cluster.NewConfig() + opts.ClusterConfig = *sarama.NewConfig() opts.ClusterConfig.Consumer.Offsets.CommitInterval = time.Second for _, opt := range options { opt(&opts) } - consumer, err := cluster.NewConsumer(opts.Brokers, opts.group(), opts.Topics, opts.clusterConfig()) + consumerGroup, err := sarama.NewConsumerGroup(opts.Brokers, opts.group(), opts.clusterConfig()) if err != nil { return nil, err } @@ -52,8 +56,9 @@ func NewSubscriber(options ...Option) (*Subscriber, error) { ErrorHandler: opts.ErrorHandler, PanicHandler: opts.PanicHandler, }, - consumer: consumer, - logger: opts.logger(), + topics: opts.Topics, + consumerGroup: consumerGroup, + logger: opts.logger(), }, nil } @@ -62,43 +67,49 @@ func NewSubscriber(options ...Option) (*Subscriber, error) { /////////////////////////////////////////////////////////////////////////////// // Listen kafka consumer -func (s *Subscriber) Listen(ctx context.Context) (err error) { -loop: +func (s *Subscriber) Listen(ctx context.Context) error { for { - if s.consumer == nil { - break + if err := s.consumerGroup.Consume(ctx, s.topics, s); err != nil { + s.processError(err) } - select { - case msg, ok := <-s.consumer.Messages(): - if !ok { - break loop - } - m := &message{ctx: ctx, msg: msg, consumer: s.consumer} - if err := s.ProcessMessage(m); err != nil { - s.logger.Error(err) - } - case err, ok := <-s.consumer.Errors(): - if !ok { - break loop - } - if err != nil { - s.processError(err) - } - case notification, ok := <-s.consumer.Notifications(): - if !ok { - break loop - } - s.processNotification(notification) - case <-ctx.Done(): - break loop + // check if context was cancelled, signaling that the consumer should stop + if ctx.Err() != nil { + return nil } } - return err +} + +// Setup is run at the beginning of a new session, before ConsumeClaim. +func (s *Subscriber) Setup(sarama.ConsumerGroupSession) error { + return nil +} + +// Cleanup is run at the end of a session, once all ConsumeClaim goroutines have exited +// but before the offsets are committed for the very last time. +func (s *Subscriber) Cleanup(sarama.ConsumerGroupSession) error { + return nil +} + +// ConsumeClaim must start a consumer loop of ConsumerGroupClaim's Messages(). +// Once the Messages() channel is closed, the Handler must finish its processing +// loop and exit. +func (s *Subscriber) ConsumeClaim(session sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error { + // NOTE: + // Do not move the code below to a goroutine. + // The `ConsumeClaim` itself is called within a goroutine, see: + // https://github.com/Shopify/sarama/blob/main/consumer_group.go#L27-L29 + for msg := range claim.Messages() { + m := &message{msg: msg, session: session} + if err := s.ProcessMessage(m); err != nil { + s.logger.Error(err) + } + } + return nil } // Close kafka consumer func (s *Subscriber) Close() error { - if err := s.consumer.Close(); err != nil { + if err := s.consumerGroup.Close(); err != nil { _ = s.ModelSubscriber.Close() return err } @@ -112,11 +123,3 @@ func (s *Subscriber) processError(err error) { s.logger.Error(err) } } - -func (s *Subscriber) processNotification(notification *cluster.Notification) { - if s.notificationHandler != nil { - s.notificationHandler(notification) - } else { - s.logger.Debugf("consumer notification: %+v", notification) - } -} diff --git a/kafka/subscriber_test.go b/kafka/subscriber_test.go index 1ba2a95..7cfdd8f 100644 --- a/kafka/subscriber_test.go +++ b/kafka/subscriber_test.go @@ -68,7 +68,7 @@ func TestNewSubscriberError(t *testing.T) { WithGroupName(``), WithKafkaVersion(sarama.V0_10_0_0), WithErrorHandler(func(msg nc.Message, err error) {}), - WithPanicHandler(func(msg nc.Message, recoverData interface{}) {}), + WithPanicHandler(func(msg nc.Message, recoverData any) {}), WithSubscriberNotificationHandler(func(notification *cluster.Notification) {}), ) assert.Error(t, err) diff --git a/mocks/publisher.go b/mocks/publisher.go index 08295b7..5a1b113 100644 --- a/mocks/publisher.go +++ b/mocks/publisher.go @@ -34,9 +34,9 @@ func (m *MockPublisher) EXPECT() *MockPublisherMockRecorder { } // Publish mocks base method -func (m *MockPublisher) Publish(ctx context.Context, messages ...interface{}) error { +func (m *MockPublisher) Publish(ctx context.Context, messages ...any) error { m.ctrl.T.Helper() - varargs := []interface{}{ctx} + varargs := []any{ctx} for _, a := range messages { varargs = append(varargs, a) } @@ -46,8 +46,8 @@ func (m *MockPublisher) Publish(ctx context.Context, messages ...interface{}) er } // Publish indicates an expected call of Publish -func (mr *MockPublisherMockRecorder) Publish(ctx interface{}, messages ...interface{}) *gomock.Call { +func (mr *MockPublisherMockRecorder) Publish(ctx any, messages ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx}, messages...) + varargs := append([]any{ctx}, messages...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Publish", reflect.TypeOf((*MockPublisher)(nil).Publish), varargs...) } diff --git a/mocks/receiver.go b/mocks/receiver.go index 0a26f8d..b008249 100644 --- a/mocks/receiver.go +++ b/mocks/receiver.go @@ -42,7 +42,7 @@ func (m *MockReceiver) Receive(msg notificationcenter.Message) error { } // Receive indicates an expected call of Receive -func (mr *MockReceiverMockRecorder) Receive(msg interface{}) *gomock.Call { +func (mr *MockReceiverMockRecorder) Receive(msg any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Receive", reflect.TypeOf((*MockReceiver)(nil).Receive), msg) } diff --git a/mocks/subscriber.go b/mocks/subscriber.go index 8b43246..1c2e013 100644 --- a/mocks/subscriber.go +++ b/mocks/subscriber.go @@ -57,7 +57,7 @@ func (m *MockSubscriber) Subscribe(ctx context.Context, receiver notificationcen } // Subscribe indicates an expected call of Subscribe -func (mr *MockSubscriberMockRecorder) Subscribe(ctx, receiver interface{}) *gomock.Call { +func (mr *MockSubscriberMockRecorder) Subscribe(ctx, receiver any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Subscribe", reflect.TypeOf((*MockSubscriber)(nil).Subscribe), ctx, receiver) } @@ -71,7 +71,7 @@ func (m *MockSubscriber) Listen(ctx context.Context) error { } // Listen indicates an expected call of Listen -func (mr *MockSubscriberMockRecorder) Listen(ctx interface{}) *gomock.Call { +func (mr *MockSubscriberMockRecorder) Listen(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Listen", reflect.TypeOf((*MockSubscriber)(nil).Listen), ctx) } diff --git a/nats/publisher.go b/nats/publisher.go index 11115cb..fee0fde 100644 --- a/nats/publisher.go +++ b/nats/publisher.go @@ -62,7 +62,7 @@ func MustNewPublisher(options ...Option) *Publisher { } // Publish one or more messages to the pub-service -func (s *Publisher) Publish(ctx context.Context, messages ...interface{}) (err error) { +func (s *Publisher) Publish(ctx context.Context, messages ...any) (err error) { buff := bytebuffer.AcquireBuffer() defer func() { bytebuffer.ReleaseBuffer(buff) diff --git a/nats/subscriber.go b/nats/subscriber.go index ed637aa..156dd06 100644 --- a/nats/subscriber.go +++ b/nats/subscriber.go @@ -14,8 +14,8 @@ import ( ) type loggerInterface interface { - Error(params ...interface{}) - Debugf(msg string, params ...interface{}) + Error(params ...any) + Debugf(msg string, params ...any) } // Subscriber for NATS queue diff --git a/natstream/options.go b/natstream/options.go index 58036b9..b17a366 100644 --- a/natstream/options.go +++ b/natstream/options.go @@ -15,8 +15,8 @@ import ( ) type loggerInterface interface { - Error(params ...interface{}) - Debugf(msg string, params ...interface{}) + Error(params ...any) + Debugf(msg string, params ...any) } // Options of the NATS wrapper diff --git a/natstream/publisher.go b/natstream/publisher.go index 23124c4..fe96870 100644 --- a/natstream/publisher.go +++ b/natstream/publisher.go @@ -62,7 +62,7 @@ func MustNewPublisher(options ...Option) *Publisher { } // Publish one or more messages to the pub-service -func (s *Publisher) Publish(ctx context.Context, messages ...interface{}) (err error) { +func (s *Publisher) Publish(ctx context.Context, messages ...any) (err error) { buff := bytebuffer.AcquireBuffer() defer func() { bytebuffer.ReleaseBuffer(buff) diff --git a/pg/logger_std.go b/pg/logger_std.go index 5192103..2bd87f6 100644 --- a/pg/logger_std.go +++ b/pg/logger_std.go @@ -13,17 +13,17 @@ func nlog() *LoggerStd { } // Info level printing -func (l *LoggerStd) Info(params ...interface{}) { +func (l *LoggerStd) Info(params ...any) { l.lg().Println(params...) } // Error level printing -func (l *LoggerStd) Error(params ...interface{}) { +func (l *LoggerStd) Error(params ...any) { l.lg().Println(params...) } // Debugf level printing -func (l *LoggerStd) Debugf(msg string, params ...interface{}) { +func (l *LoggerStd) Debugf(msg string, params ...any) { l.lg().Printf(msg, params...) } diff --git a/pg/subscriber.go b/pg/subscriber.go index 40d8f63..f3f4d2f 100644 --- a/pg/subscriber.go +++ b/pg/subscriber.go @@ -15,9 +15,9 @@ import ( ) type loggerInterface interface { - Info(params ...interface{}) - Error(params ...interface{}) - Debugf(msg string, params ...interface{}) + Info(params ...any) + Error(params ...any) + Debugf(msg string, params ...any) } // Subscriber for kafka diff --git a/publisher.go b/publisher.go index c232546..50dc86d 100644 --- a/publisher.go +++ b/publisher.go @@ -1,35 +1,39 @@ // -// @project geniusrabbit.com 2015 – 2016, 2019 - 2020 -// @author Dmitry Ponomarev 2015 – 2016, 2019 - 2020 +// @project geniusrabbit.com 2015 – 2016, 2019 - 2022 +// @author Dmitry Ponomarev 2015 – 2016, 2019 - 2022 // package notificationcenter -import "context" +import ( + "context" + + "go.uber.org/multierr" +) // Publisher pipeline base declaration //go:generate mockgen -source $GOFILE -package mocks -destination mocks/publisher.go type Publisher interface { // Publish one or more messages to the pub-service - Publish(ctx context.Context, messages ...interface{}) error + Publish(ctx context.Context, messages ...any) error } // MultiPublisher wrapper type MultiPublisher []Publisher // Publish one or more messages to the banch of pub-services -func (p MultiPublisher) Publish(ctx context.Context, messages ...interface{}) error { - var errs multiError +func (p MultiPublisher) Publish(ctx context.Context, messages ...any) error { + var errs error for _, pub := range p { - errs.Add(pub.Publish(ctx, messages...)) + errs = multierr.Append(errs, pub.Publish(ctx, messages...)) } - return errs.AsError() + return errs } // FuncPublisher provides custom function wrapper for the custom publisher processor -type FuncPublisher func(context.Context, ...interface{}) error +type FuncPublisher func(context.Context, ...any) error // Publish method call the original custom publisher function -func (f FuncPublisher) Publish(ctx context.Context, messages ...interface{}) error { +func (f FuncPublisher) Publish(ctx context.Context, messages ...any) error { return f(ctx, messages...) } diff --git a/publisher_test.go b/publisher_test.go index 1e72501..c5b3e18 100644 --- a/publisher_test.go +++ b/publisher_test.go @@ -10,13 +10,13 @@ import ( func TestMultiPublisher(t *testing.T) { sum := 0 pubs := MultiPublisher{ - FuncPublisher(func(ctx context.Context, messages ...interface{}) error { + FuncPublisher(func(ctx context.Context, messages ...any) error { for _, v := range messages { sum += v.(int) } return nil }), - FuncPublisher(func(ctx context.Context, messages ...interface{}) error { + FuncPublisher(func(ctx context.Context, messages ...any) error { for _, v := range messages { sum += v.(int) } diff --git a/receiver.go b/receiver.go index 129e1a4..52961cf 100644 --- a/receiver.go +++ b/receiver.go @@ -1,6 +1,6 @@ // -// @project geniusrabbit.com 2015 – 2016, 2019 - 2020 -// @author Dmitry Ponomarev 2015 – 2016, 2019 - 2020 +// @project geniusrabbit.com 2015 – 2016, 2019 - 2022 +// @author Dmitry Ponomarev 2015 – 2016, 2019 - 2022 // package notificationcenter diff --git a/receiver_func.go b/receiver_func.go index e0478aa..94d0cf7 100644 --- a/receiver_func.go +++ b/receiver_func.go @@ -11,7 +11,7 @@ import ( var errInvalidReturnType = errors.New("invalid return types") // ReceiverFrom converts income handler type to Receiver interface -func ReceiverFrom(handler interface{}) Receiver { +func ReceiverFrom(handler any) Receiver { switch h := handler.(type) { case Receiver: return h @@ -29,7 +29,7 @@ var ( ) // ExtFuncReceiver wraps function argument with arbitrary input data type -func ExtFuncReceiver(f interface{}, decs ...decoder.Decoder) Receiver { +func ExtFuncReceiver(f any, decs ...decoder.Decoder) Receiver { fv := reflect.ValueOf(f) if fv.Kind() != reflect.Func { panic("argument must be a function") @@ -95,7 +95,7 @@ func ExtFuncReceiver(f interface{}, decs ...decoder.Decoder) Receiver { }) } -func newValue(t reflect.Type) (reflect.Value, interface{}) { +func newValue(t reflect.Type) (reflect.Value, any) { if t.Kind() == reflect.Ptr { return newValue(t.Elem()) } diff --git a/redis/message.go b/redis/message.go index 5626e01..da5b526 100644 --- a/redis/message.go +++ b/redis/message.go @@ -3,7 +3,7 @@ package redis import ( "context" - "github.com/go-redis/redis" + "github.com/go-redis/redis/v8" ) type message struct { diff --git a/redis/options.go b/redis/options.go index d07574f..db916b0 100644 --- a/redis/options.go +++ b/redis/options.go @@ -8,12 +8,12 @@ import ( nc "github.com/geniusrabbit/notificationcenter" "github.com/geniusrabbit/notificationcenter/encoder" "github.com/geniusrabbit/notificationcenter/internal/logger" - "github.com/go-redis/redis" + "github.com/go-redis/redis/v8" ) type loggerInterface interface { - Error(params ...interface{}) - Debugf(msg string, params ...interface{}) + Error(params ...any) + Debugf(msg string, params ...any) } // Option of the Redis subscriber or publisher diff --git a/redis/options_test.go b/redis/options_test.go index 137d4df..22a0bb2 100644 --- a/redis/options_test.go +++ b/redis/options_test.go @@ -6,7 +6,7 @@ import ( nc "github.com/geniusrabbit/notificationcenter" "github.com/geniusrabbit/notificationcenter/encoder" "github.com/geniusrabbit/notificationcenter/internal/logger" - "github.com/go-redis/redis" + "github.com/go-redis/redis/v8" "github.com/stretchr/testify/assert" ) @@ -44,7 +44,7 @@ func TestOptionWithURL(t *testing.T) { WithErrorHandler(func(msg nc.Message, err error) {})(&options) assert.NotNil(t, options.ErrorHandler, "invalid error handler") - WithPanicHandler(func(msg nc.Message, recoverData interface{}) {})(&options) + WithPanicHandler(func(msg nc.Message, recoverData any) {})(&options) assert.NotNil(t, options.PanicHandler, "invalid panic handler") WithLogger(logger.DefaultLogger)(&options) diff --git a/redis/publisher.go b/redis/publisher.go index 3d9b3f7..db11a72 100644 --- a/redis/publisher.go +++ b/redis/publisher.go @@ -3,11 +3,12 @@ package redis import ( "context" + "github.com/go-redis/redis/v8" + "go.uber.org/multierr" + nc "github.com/geniusrabbit/notificationcenter" "github.com/geniusrabbit/notificationcenter/encoder" "github.com/geniusrabbit/notificationcenter/internal/bytebuffer" - "github.com/go-redis/redis" - "go.uber.org/multierr" ) // Publisher for NATS queue @@ -53,7 +54,7 @@ func MustNewPublisher(options ...Option) *Publisher { } // Publish one or more messages to the pub-service -func (s *Publisher) Publish(ctx context.Context, messages ...interface{}) (err error) { +func (s *Publisher) Publish(ctx context.Context, messages ...any) (err error) { buff := bytebuffer.AcquireBuffer() defer func() { bytebuffer.ReleaseBuffer(buff) @@ -68,7 +69,7 @@ func (s *Publisher) Publish(ctx context.Context, messages ...interface{}) (err e buff.Reset() if err = s.encoder(msg, buff); err == nil { for _, channel := range s.channels { - if pubErr := s.cli.Publish(channel, buff.Bytes()).Err(); pubErr != nil { + if pubErr := s.cli.Publish(ctx, channel, buff.Bytes()).Err(); pubErr != nil { err = multierr.Append(err, pubErr) } } diff --git a/redis/subscriber.go b/redis/subscriber.go index 291c1ba..0f20205 100644 --- a/redis/subscriber.go +++ b/redis/subscriber.go @@ -3,7 +3,7 @@ package redis import ( "context" - "github.com/go-redis/redis" + "github.com/go-redis/redis/v8" nc "github.com/geniusrabbit/notificationcenter" ) @@ -67,7 +67,7 @@ func (s *Subscriber) Listen(ctx context.Context) error { } func (s *Subscriber) subscribe(ctx context.Context) { - s.sub = s.cli.Subscribe(s.channels...) + s.sub = s.cli.Subscribe(ctx, s.channels...) for msg := range s.sub.Channel() { s.message(ctx, msg) } diff --git a/registry.go b/registry.go index 2e666a0..ef3f802 100644 --- a/registry.go +++ b/registry.go @@ -8,6 +8,7 @@ import ( "sync/atomic" "github.com/pkg/errors" + "go.uber.org/multierr" ) // Error list... @@ -61,7 +62,7 @@ func (r *Registry) Subscriber(name string) Subscriber { // "notifications", nats.MustNewSubscriber(), // ) // ``` -func (r *Registry) Register(params ...interface{}) error { +func (r *Registry) Register(params ...any) error { var name string r.mx.Lock() defer r.mx.Unlock() @@ -92,7 +93,7 @@ func (r *Registry) Register(params ...interface{}) error { } // Publish one or more messages to the pub-service -func (r *Registry) Publish(ctx context.Context, name string, messages ...interface{}) error { +func (r *Registry) Publish(ctx context.Context, name string, messages ...any) error { pub := r.Publisher(name) if pub == nil { return errors.Wrapf(ErrUndefinedPublisherInterface, name) @@ -128,30 +129,27 @@ func (r *Registry) Listen(ctx context.Context) (err error) { // Close notification center func (r *Registry) Close() error { - var errors []error + var errors error r.mx.Lock() defer r.mx.Unlock() for _, pub := range r.publishers { if cl, ok := pub.(io.Closer); ok { if err := cl.Close(); err != nil { - errors = append(errors, err) + errors = multierr.Append(errors, err) } } } for _, sub := range r.subscribers { if cl, ok := sub.(io.Closer); ok { if err := cl.Close(); err != nil { - errors = append(errors, err) + errors = multierr.Append(errors, err) } } } for i := int32(0); i < atomic.LoadInt32(&r.closeEventCount); i++ { r.closeEvent <- true } - if len(errors) > 0 { - return MultiError(errors...) - } - return nil + return errors } // OnClose event will be executed only after closing all interfaces diff --git a/registry_test.go b/registry_test.go index 35fec72..21c693a 100644 --- a/registry_test.go +++ b/registry_test.go @@ -9,7 +9,7 @@ import ( type testPublisher struct{} -func (p *testPublisher) Publish(ctx context.Context, messages ...interface{}) error { return nil } +func (p *testPublisher) Publish(ctx context.Context, messages ...any) error { return nil } type testSubscriber struct{} diff --git a/wrappers/concurrency/options.go b/wrappers/concurrency/options.go index b74db98..ae05408 100644 --- a/wrappers/concurrency/options.go +++ b/wrappers/concurrency/options.go @@ -13,7 +13,7 @@ func WithWorkerPoolSize(size int) Option { } // WithRecoverHandler defined error handler -func WithRecoverHandler(f func(interface{})) Option { +func WithRecoverHandler(f func(any)) Option { return func() rpool.Option { return rpool.WithRecoverHandler(f) } diff --git a/wrappers/concurrency/receiver.go b/wrappers/concurrency/receiver.go index 62936ad..54a92bd 100644 --- a/wrappers/concurrency/receiver.go +++ b/wrappers/concurrency/receiver.go @@ -32,7 +32,7 @@ func (r *receiver) Receive(msg nc.Message) error { return nil } -func (r *receiver) executor(msg interface{}) { +func (r *receiver) executor(msg any) { ncMsg := msg.(nc.Message) err := r.receiver.Receive(ncMsg) if err != nil { diff --git a/wrappers/once/bigcache/checker.go b/wrappers/once/bigcache/checker.go index 6b69863..128e5fa 100644 --- a/wrappers/once/bigcache/checker.go +++ b/wrappers/once/bigcache/checker.go @@ -33,12 +33,12 @@ func NewDefault(duration time.Duration) (*Checker, error) { } // IsSkip message if was sent -func (ch *Checker) IsSkip(msg interface{}) bool { +func (ch *Checker) IsSkip(msg any) bool { val, _ := ch.cache.Get(objecthash.Hash(msg)) return len(val) == 1 && val[0] == 't' } // MarkAsSent message to the publisher -func (ch *Checker) MarkAsSent(msg interface{}) error { +func (ch *Checker) MarkAsSent(msg any) error { return ch.cache.Set(objecthash.Hash(msg), []byte(`t`)) } diff --git a/wrappers/once/checker.go b/wrappers/once/checker.go index b2f8eb7..82ecea7 100644 --- a/wrappers/once/checker.go +++ b/wrappers/once/checker.go @@ -2,6 +2,6 @@ package once // Checker provides test interface of messages type Checker interface { - IsSkip(msg interface{}) bool - MarkAsSent(msg interface{}) error + IsSkip(msg any) bool + MarkAsSent(msg any) error } diff --git a/wrappers/once/publisher.go b/wrappers/once/publisher.go index 228125e..d666ccf 100644 --- a/wrappers/once/publisher.go +++ b/wrappers/once/publisher.go @@ -28,7 +28,7 @@ func MewPublisherWrapper(pub nc.Publisher, checker Checker) *PublisherWrapper { } // Publish one or more messages to the pub-service if will pass conditions -func (wr *PublisherWrapper) Publish(ctx context.Context, messages ...interface{}) error { +func (wr *PublisherWrapper) Publish(ctx context.Context, messages ...any) error { for _, msg := range messages { if wr.checker.IsSkip(msg) { continue diff --git a/wrappers/once/redis/checker.go b/wrappers/once/redis/checker.go index 2cbfb6d..c371585 100644 --- a/wrappers/once/redis/checker.go +++ b/wrappers/once/redis/checker.go @@ -1,10 +1,11 @@ package redis import ( + "context" "time" "github.com/geniusrabbit/notificationcenter/internal/objecthash" - "github.com/go-redis/redis" + "github.com/go-redis/redis/v8" ) // Checker provides inmemory messages test @@ -24,12 +25,12 @@ func NewByHost(host string, lifetime time.Duration) *Checker { } // IsSkip message if was sent -func (ch *Checker) IsSkip(msg interface{}) bool { - val, _ := ch.client.Get(objecthash.Hash(msg)).Result() +func (ch *Checker) IsSkip(ctx context.Context, msg any) bool { + val, _ := ch.client.Get(ctx, objecthash.Hash(msg)).Result() return len(val) == 1 && val == `t` } // MarkAsSent message to the publisher -func (ch *Checker) MarkAsSent(msg interface{}) error { - return ch.client.SetNX(objecthash.Hash(msg), []byte(`t`), ch.lifetime).Err() +func (ch *Checker) MarkAsSent(ctx context.Context, msg any) error { + return ch.client.SetNX(ctx, objecthash.Hash(msg), []byte(`t`), ch.lifetime).Err() } diff --git a/wrappers/once/redis/checker_test.go b/wrappers/once/redis/checker_test.go index 3acc7ca..06d90de 100644 --- a/wrappers/once/redis/checker_test.go +++ b/wrappers/once/redis/checker_test.go @@ -1,12 +1,13 @@ package redis import ( + "context" "testing" "time" - "github.com/alicebob/miniredis" - "github.com/elliotchance/redismock" - "github.com/go-redis/redis" + "github.com/alicebob/miniredis/v2" + "github.com/elliotchance/redismock/v8" + "github.com/go-redis/redis/v8" "github.com/stretchr/testify/assert" ) @@ -19,12 +20,13 @@ func newTestRedis(mr *miniredis.Miniredis) *redismock.ClientMock { } func TestRedisChecker(t *testing.T) { + ctx := context.TODO() msg := struct{ s string }{s: `test`} mr, err := miniredis.Run() assert.NoError(t, err) defer mr.Close() checker := New(newTestRedis(mr), time.Minute) - assert.False(t, checker.IsSkip(msg)) - assert.NoError(t, checker.MarkAsSent(msg)) - assert.True(t, checker.IsSkip(msg)) + assert.False(t, checker.IsSkip(ctx, msg)) + assert.NoError(t, checker.MarkAsSent(ctx, msg)) + assert.True(t, checker.IsSkip(ctx, msg)) } From 1fb241a2a8b8db7a4c11a021a6c6b25048a224d3 Mon Sep 17 00:00:00 2001 From: Dmitry Ponomarev Date: Fri, 25 Feb 2022 19:43:14 +0100 Subject: [PATCH 2/3] Add support generic subscriber to make esear of using data mapping --- README.md | 16 +++++------ center.go | 2 +- dummy/dummy_test.go | 2 +- dummy/subscriber.go | 2 +- go.mod | 7 +++-- go.sum | 39 +++++++-------------------- gochan/go.go | 2 +- gochan/go_test.go | 2 +- internal/tests/registry_test.go | 4 +-- interval/options.go | 2 +- interval/subscriber.go | 2 +- interval/subscriber_test.go | 2 +- kafka/message_test.go | 4 +-- kafka/options.go | 16 +++-------- kafka/publisher.go | 10 +++---- kafka/record.go | 4 +-- kafka/subscriber.go | 14 +++------- kafka/subscriber_test.go | 4 +-- mocks/receiver.go | 2 +- mocks/subscriber.go | 2 +- nats/options.go | 6 ++--- nats/publisher.go | 6 ++--- nats/subscriber.go | 2 +- natstream/options.go | 6 ++--- natstream/publisher.go | 6 ++--- natstream/subscriber.go | 2 +- pg/README.md | 4 +-- pg/subscriber.go | 2 +- pg/subscriber_test.go | 2 +- publisher.go | 4 +-- receiver.go | 4 +-- receiver_func.go | 7 ++++- redis/options.go | 6 ++--- redis/options_test.go | 6 ++--- redis/publisher.go | 6 ++--- redis/subscriber.go | 2 +- redis/subsub_test.go | 2 +- registry.go | 4 +-- wrappers/concurrency/options.go | 2 +- wrappers/concurrency/receiver.go | 13 +++++---- wrappers/concurrency/receiver_test.go | 4 +-- wrappers/once/bigcache/checker.go | 2 +- wrappers/once/publisher.go | 2 +- wrappers/once/publisher_test.go | 4 +-- wrappers/once/redis/checker.go | 2 +- 45 files changed, 104 insertions(+), 140 deletions(-) diff --git a/README.md b/README.md index 9edc48c..6676c90 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Basic examples of usage. ```go import( - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) ``` @@ -72,8 +72,8 @@ events.Publish(context.Background(), message{title: "event 2"}) ```go import ( - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/nats" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/nats" ) func main() { @@ -84,15 +84,15 @@ func main() { nc.Register("refresh", interval.NewSubscriber(time.Minute * 5)) // Add new receiver to process the stream "events" - nc.Subscribe("events", nc.FuncReceiver(ctx, func(msg nc.Message) error { + nc.Subscribe("events", func(msg nc.Message) error { fmt.Printf("%v\n", msg.Data()) - return nil - })) + return msg.Ack() + }) // Add new time interval receiver to refresh the data every 5 minutes - nc.Subscribe("refresh", nc.FuncReceiver(ctx, func(msg nc.Message) error { + nc.Subscribe("refresh", func(msg nc.Message) error { return db.Reload() - })) + }) // Run subscriber listeners nc.Listen(ctx) diff --git a/center.go b/center.go index 282bdfa..e45fb20 100644 --- a/center.go +++ b/center.go @@ -42,7 +42,7 @@ func Publish(ctx context.Context, name string, messages ...any) error { } // Subscribe new handler on some particular subscriber interface by name -func Subscribe(ctx context.Context, name string, receiver Receiver) error { +func Subscribe(ctx context.Context, name string, receiver any) error { return DefaultRegistry.Subscribe(ctx, name, receiver) } diff --git a/dummy/dummy_test.go b/dummy/dummy_test.go index a20643f..7d281c8 100644 --- a/dummy/dummy_test.go +++ b/dummy/dummy_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" "github.com/stretchr/testify/assert" ) diff --git a/dummy/subscriber.go b/dummy/subscriber.go index a5ec18f..7dcbf35 100644 --- a/dummy/subscriber.go +++ b/dummy/subscriber.go @@ -3,7 +3,7 @@ package dummy import ( "context" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) // Subscriber struct diff --git a/go.mod b/go.mod index 25ae4ca..b964a02 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/geniusrabbit/notificationcenter +module github.com/geniusrabbit/notificationcenter/v2 go 1.18 @@ -6,9 +6,8 @@ require ( github.com/Shopify/sarama v1.32.0 github.com/alicebob/miniredis/v2 v2.15.1 github.com/allegro/bigcache v1.2.1 - github.com/bsm/sarama-cluster v2.1.15+incompatible - github.com/demdxx/gocast v1.0.1 - github.com/demdxx/rpool v0.0.0-20200317152850-d737c64d8aaf + github.com/demdxx/gocast v1.2.0 + github.com/demdxx/rpool/v2 v2.0.1 github.com/elliotchance/redismock/v8 v8.11.0 github.com/go-redis/redis/v8 v8.11.4 github.com/golang/mock v1.6.0 diff --git a/go.sum b/go.sum index 63828ec..97ef71e 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= -github.com/Shopify/sarama v1.29.1 h1:wBAacXbYVLmWieEA/0X/JagDdCZ8NVFOfS6l6+2u5S0= -github.com/Shopify/sarama v1.29.1/go.mod h1:mdtqvCSg8JOxk8PmpTNGyo6wzd4BMm4QXSfDnTXmgkE= github.com/Shopify/sarama v1.32.0 h1:P+RUjEaRU0GMMbYexGMDyrMkLhbbBVUVISDywi+IlFU= github.com/Shopify/sarama v1.32.0/go.mod h1:+EmJJKZWVT/faR9RcOxJerP+LId4iWdQPBGLy1Y1Njs= -github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= -github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/Shopify/toxiproxy/v2 v2.3.0 h1:62YkpiP4bzdhKMH+6uC5E95y608k3zDwdzuBMsnn3uQ= github.com/Shopify/toxiproxy/v2 v2.3.0/go.mod h1:KvQTtB6RjCJY4zqNJn7C7JDFgsG5uoHYDirfUfpIm0c= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= @@ -17,8 +14,6 @@ github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2uc github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM= github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/bsm/sarama-cluster v2.1.15+incompatible h1:RkV6WiNRnqEEbp81druK8zYhmnIgdOjqSVi0+9Cnl2A= -github.com/bsm/sarama-cluster v2.1.15+incompatible/go.mod h1:r7ao+4tTNXvWm+VRpRJchr2kQhqxgmAp2iEX5W96gMM= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -32,10 +27,10 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/demdxx/gocast v1.0.1 h1:5dIlibBCaaGD4SCBWNHyKUt3DNlbcIbtoJjMH1CNgRY= -github.com/demdxx/gocast v1.0.1/go.mod h1:doeaWGKAe/UuiDhJ3tmbSK2RwN5qK+8Z18RRVzHLNsA= -github.com/demdxx/rpool v0.0.0-20200317152850-d737c64d8aaf h1:qTk+vPwzCp/on8DpTLDizwwvo08DNlj0ptDYwP+R4ng= -github.com/demdxx/rpool v0.0.0-20200317152850-d737c64d8aaf/go.mod h1:x9oXikUwI05ecNFxo0JUpQ6hABl2lNtKMXv2wlDduyk= +github.com/demdxx/gocast v1.2.0 h1:Z9zVpAjyTWJIJwFFynnOoP30yxot4Y2QafNPSD+VEEo= +github.com/demdxx/gocast v1.2.0/go.mod h1:RTyqNS6BdIq/19jJX96PlVhfqG31tldKMnpVJnPa3pw= +github.com/demdxx/rpool/v2 v2.0.1 h1:ZxgPqK4u5bn4xvr2OcMKMwalUmcKyn3LIacg1FMGvwM= +github.com/demdxx/rpool/v2 v2.0.1/go.mod h1:iJef6bxMV9GPN8bi+CrmJEYAoUvR6l5qjXfNwQcYf20= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/eapache/go-resiliency v1.2.0 h1:v7g92e/KSN71Rq7vSThKaWIq68fL4YHvWyiUKorFR1Q= @@ -50,8 +45,7 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= -github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY= -github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= +github.com/frankban/quicktest v1.14.2 h1:SPb1KFFmM+ybpEjPUhCCkZOM5xlovT5UbrMvWnXyBns= github.com/frankban/quicktest v1.14.2/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= @@ -75,8 +69,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -84,8 +76,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= @@ -125,13 +117,11 @@ github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJk github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.12.2 h1:2KCfW3I9M7nSc5wOqXAlW2v2U6v+w6cbjvbfp+OykW8= -github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/compress v1.14.4 h1:eijASRJcobkVtSt81Olfh7JX43osYLwy5krOJo6YEu4= github.com/klauspost/compress v1.14.4/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -155,7 +145,6 @@ github.com/nats-io/nats-server/v2 v2.2.6 h1:FPK9wWx9pagxcw14s8W9rlfzfyHm61uNLnJy github.com/nats-io/nats-server/v2 v2.2.6/go.mod h1:sEnFaxqe09cDmfMgACxZbziXnhQFhwk+aKkZjBBRYrI= github.com/nats-io/nats-streaming-server v0.22.0 h1:2egnq86o9roTqUfELlqykf7ZZkNvRsXjVf4EbaLysHo= github.com/nats-io/nats-streaming-server v0.22.0/go.mod h1:Jyu3eUQaUAjwd5TiBuLagKdQRofPrHoIXt1kL0U/e5o= -github.com/nats-io/nats.go v1.11.0 h1:L263PZkrmkRJRJT2YHU8GwWWvEvmr9/LUKuJTXsF32k= github.com/nats-io/nats.go v1.11.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= github.com/nats-io/nats.go v1.13.0 h1:LvYqRB5epIzZWQp6lmeltOOZNLqCvm4b+qfvzZO03HE= github.com/nats-io/nats.go v1.13.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= @@ -164,7 +153,6 @@ github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8= github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/nats-io/stan.go v0.9.0 h1:TB73Y31au++0sU0VmnBy2pYkSrwH0zUFNRB9YePHqC4= github.com/nats-io/stan.go v0.9.0/go.mod h1:0jEuBXKauB1HHJswHM/lx05K48TJ1Yxj6VIfM4k+aB4= github.com/nats-io/stan.go v0.10.2 h1:gQLd05LhzmhFkHm3/qP/klYHfM/hys45GyHa1Uly/kI= github.com/nats-io/stan.go v0.10.2/go.mod h1:vo2ax8K2IxaR3JtEMLZRFKIdoK/3o1/PKueapB7ezX0= @@ -186,8 +174,6 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pierrec/lz4 v2.6.0+incompatible h1:Ix9yFKn1nSPBLFl/yZknTp8TU5G4Ps0JDmguYK6iH1A= -github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -203,6 +189,7 @@ github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3x github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= @@ -221,8 +208,6 @@ github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/X github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.0/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= -github.com/xdg/scram v1.0.3/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= -github.com/xdg/stringprep v1.0.3/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= @@ -243,8 +228,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -263,8 +246,6 @@ golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q= -golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -305,8 +286,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/gochan/go.go b/gochan/go.go index e78b44e..4cbc50f 100644 --- a/gochan/go.go +++ b/gochan/go.go @@ -6,7 +6,7 @@ import ( "encoding/json" "io" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) func jsonEncoder(msg any, wr io.Writer) error { diff --git a/gochan/go_test.go b/gochan/go_test.go index 927dc25..ecdceb0 100644 --- a/gochan/go_test.go +++ b/gochan/go_test.go @@ -6,7 +6,7 @@ import ( "sync" "testing" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" "github.com/stretchr/testify/assert" ) diff --git a/internal/tests/registry_test.go b/internal/tests/registry_test.go index 3ad49de..157a3a1 100644 --- a/internal/tests/registry_test.go +++ b/internal/tests/registry_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/assert" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/dummy" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/dummy" ) func TestRegistry(t *testing.T) { diff --git a/interval/options.go b/interval/options.go index af28d0f..b5fb068 100644 --- a/interval/options.go +++ b/interval/options.go @@ -1,7 +1,7 @@ package interval import ( - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) type handler func() any diff --git a/interval/subscriber.go b/interval/subscriber.go index 28444d5..bed748e 100644 --- a/interval/subscriber.go +++ b/interval/subscriber.go @@ -4,7 +4,7 @@ import ( "context" "time" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) type interval struct { diff --git a/interval/subscriber_test.go b/interval/subscriber_test.go index 334b0e8..2f7341b 100644 --- a/interval/subscriber_test.go +++ b/interval/subscriber_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" "github.com/stretchr/testify/assert" ) diff --git a/kafka/message_test.go b/kafka/message_test.go index f4aea2d..207a38e 100644 --- a/kafka/message_test.go +++ b/kafka/message_test.go @@ -10,8 +10,8 @@ import ( "github.com/Shopify/sarama" "github.com/stretchr/testify/assert" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/bytebuffer" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/bytebuffer" ) type testGroupSession struct{} diff --git a/kafka/options.go b/kafka/options.go index f8c79d3..b567363 100644 --- a/kafka/options.go +++ b/kafka/options.go @@ -8,9 +8,9 @@ import ( "github.com/Shopify/sarama" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/logger" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/logger" ) // Options for publisher or subscriber @@ -42,9 +42,6 @@ type Options struct { // PublisherSuccessHandler provides handler of message send success PublisherSuccessHandler PublisherSuccessHandler - // SubscriberNotificationHandler provides handler of received messages - SubscriberNotificationHandler SubscriberNotificationHandler - // Message encoder interface Encoder encoder.Encoder @@ -207,10 +204,3 @@ func WithPublisherSuccessHandler(h PublisherSuccessHandler) Option { options.PublisherSuccessHandler = h } } - -// WithSubscriberNotificationHandler set handler of the cluster group notifications -func WithSubscriberNotificationHandler(h SubscriberNotificationHandler) Option { - return func(options *Options) { - options.SubscriberNotificationHandler = h - } -} diff --git a/kafka/publisher.go b/kafka/publisher.go index 291b1f8..fc99ccb 100644 --- a/kafka/publisher.go +++ b/kafka/publisher.go @@ -1,6 +1,6 @@ // -// @project geniusrabbit.com 2015, 2019 - 2020 -// @author Dmitry Ponomarev 2015, 2019 - 2020 +// @project geniusrabbit.com 2015, 2019 - 2022 +// @author Dmitry Ponomarev 2015, 2019 - 2022 // // Config example @@ -16,9 +16,9 @@ import ( "github.com/Shopify/sarama" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/bytebuffer" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/bytebuffer" ) // PublisherErrorHandler callback function diff --git a/kafka/record.go b/kafka/record.go index 326a315..950001a 100644 --- a/kafka/record.go +++ b/kafka/record.go @@ -1,6 +1,6 @@ // -// @project geniusrabbit.com 2015 – 2016, 2019 -// @author Dmitry Ponomarev 2015 – 2016, 2019 +// @project geniusrabbit.com 2015 – 2016, 2019 – 2022 +// @author Dmitry Ponomarev 2015 – 2016, 2019 – 2022 // package kafka diff --git a/kafka/subscriber.go b/kafka/subscriber.go index e24cee2..97a0ffa 100644 --- a/kafka/subscriber.go +++ b/kafka/subscriber.go @@ -1,6 +1,6 @@ // -// @project geniusrabbit.com 2015, 2019 - 2020 -// @author Dmitry Ponomarev 2015, 2019 - 2020 +// @project geniusrabbit.com 2015, 2019 - 2022 +// @author Dmitry Ponomarev 2015, 2019 - 2022 // package kafka @@ -10,8 +10,7 @@ import ( "time" "github.com/Shopify/sarama" - cluster "github.com/bsm/sarama-cluster" - "github.com/geniusrabbit/notificationcenter" + "github.com/geniusrabbit/notificationcenter/v2" ) type loggerInterface interface { @@ -19,9 +18,6 @@ type loggerInterface interface { Debugf(msg string, params ...any) } -// SubscriberNotificationHandler callback function -type SubscriberNotificationHandler func(notification *cluster.Notification) - // Subscriber for kafka type Subscriber struct { notificationcenter.ModelSubscriber @@ -29,12 +25,8 @@ type Subscriber struct { topics []string // consumer object which receive the messages - // consumer *cluster.Consumer consumerGroup sarama.ConsumerGroup - // notificationHandler callback - notificationHandler SubscriberNotificationHandler - // logger interface logger loggerInterface } diff --git a/kafka/subscriber_test.go b/kafka/subscriber_test.go index 7cfdd8f..df6c421 100644 --- a/kafka/subscriber_test.go +++ b/kafka/subscriber_test.go @@ -5,10 +5,9 @@ import ( "testing" "github.com/Shopify/sarama" - cluster "github.com/bsm/sarama-cluster" "github.com/stretchr/testify/assert" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) const ( @@ -69,7 +68,6 @@ func TestNewSubscriberError(t *testing.T) { WithKafkaVersion(sarama.V0_10_0_0), WithErrorHandler(func(msg nc.Message, err error) {}), WithPanicHandler(func(msg nc.Message, recoverData any) {}), - WithSubscriberNotificationHandler(func(notification *cluster.Notification) {}), ) assert.Error(t, err) } diff --git a/mocks/receiver.go b/mocks/receiver.go index b008249..6f9e1c6 100644 --- a/mocks/receiver.go +++ b/mocks/receiver.go @@ -5,7 +5,7 @@ package mocks import ( - notificationcenter "github.com/geniusrabbit/notificationcenter" + notificationcenter "github.com/geniusrabbit/notificationcenter/v2" gomock "github.com/golang/mock/gomock" reflect "reflect" ) diff --git a/mocks/subscriber.go b/mocks/subscriber.go index 1c2e013..aafc6d3 100644 --- a/mocks/subscriber.go +++ b/mocks/subscriber.go @@ -6,7 +6,7 @@ package mocks import ( context "context" - notificationcenter "github.com/geniusrabbit/notificationcenter" + notificationcenter "github.com/geniusrabbit/notificationcenter/v2" gomock "github.com/golang/mock/gomock" reflect "reflect" ) diff --git a/nats/options.go b/nats/options.go index e4c257f..bcd52fa 100644 --- a/nats/options.go +++ b/nats/options.go @@ -7,9 +7,9 @@ import ( nats "github.com/nats-io/nats.go" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/logger" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/logger" ) // Options of the NATS wrapper diff --git a/nats/publisher.go b/nats/publisher.go index fee0fde..aa5fbb9 100644 --- a/nats/publisher.go +++ b/nats/publisher.go @@ -10,9 +10,9 @@ import ( nats "github.com/nats-io/nats.go" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/bytebuffer" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/bytebuffer" ) // Publisher provides functionality to work with NATS queue diff --git a/nats/subscriber.go b/nats/subscriber.go index 156dd06..dea4111 100644 --- a/nats/subscriber.go +++ b/nats/subscriber.go @@ -10,7 +10,7 @@ import ( nats "github.com/nats-io/nats.go" - "github.com/geniusrabbit/notificationcenter" + "github.com/geniusrabbit/notificationcenter/v2" ) type loggerInterface interface { diff --git a/natstream/options.go b/natstream/options.go index b17a366..64e9e24 100644 --- a/natstream/options.go +++ b/natstream/options.go @@ -9,9 +9,9 @@ import ( nats "github.com/nats-io/nats.go" nstream "github.com/nats-io/stan.go" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/logger" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/logger" ) type loggerInterface interface { diff --git a/natstream/publisher.go b/natstream/publisher.go index fe96870..73a940a 100644 --- a/natstream/publisher.go +++ b/natstream/publisher.go @@ -10,9 +10,9 @@ import ( nstream "github.com/nats-io/stan.go" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/bytebuffer" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/bytebuffer" ) // Publisher for NATS queue diff --git a/natstream/subscriber.go b/natstream/subscriber.go index c112aef..606943c 100644 --- a/natstream/subscriber.go +++ b/natstream/subscriber.go @@ -10,7 +10,7 @@ import ( nstream "github.com/nats-io/stan.go" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) // Subscriber for NATS queue diff --git a/pg/README.md b/pg/README.md index cef1bf2..30956b5 100644 --- a/pg/README.md +++ b/pg/README.md @@ -82,8 +82,8 @@ AFTER INSERT OR UPDATE OR DELETE ON products ```go import ( - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/pg" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/pg" ) const connectionDNS = "postgres://connection" diff --git a/pg/subscriber.go b/pg/subscriber.go index f3f4d2f..a423641 100644 --- a/pg/subscriber.go +++ b/pg/subscriber.go @@ -11,7 +11,7 @@ import ( "github.com/lib/pq" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) type loggerInterface interface { diff --git a/pg/subscriber_test.go b/pg/subscriber_test.go index 81490ca..9ad00e1 100644 --- a/pg/subscriber_test.go +++ b/pg/subscriber_test.go @@ -9,7 +9,7 @@ import ( "sync/atomic" "testing" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" "github.com/stretchr/testify/assert" ) diff --git a/publisher.go b/publisher.go index 50dc86d..3bc9e2d 100644 --- a/publisher.go +++ b/publisher.go @@ -1,6 +1,6 @@ // -// @project geniusrabbit.com 2015 – 2016, 2019 - 2022 -// @author Dmitry Ponomarev 2015 – 2016, 2019 - 2022 +// @project geniusrabbit.com 2015 – 2016, 2019 – 2022 - 2022 +// @author Dmitry Ponomarev 2015 – 2016, 2019 – 2022 - 2022 // package notificationcenter diff --git a/receiver.go b/receiver.go index 52961cf..6320536 100644 --- a/receiver.go +++ b/receiver.go @@ -1,6 +1,6 @@ // -// @project geniusrabbit.com 2015 – 2016, 2019 - 2022 -// @author Dmitry Ponomarev 2015 – 2016, 2019 - 2022 +// @project geniusrabbit.com 2015 – 2016, 2019 – 2022 - 2022 +// @author Dmitry Ponomarev 2015 – 2016, 2019 – 2022 - 2022 // package notificationcenter diff --git a/receiver_func.go b/receiver_func.go index 94d0cf7..8e0ed8d 100644 --- a/receiver_func.go +++ b/receiver_func.go @@ -4,8 +4,9 @@ import ( "context" "reflect" - "github.com/geniusrabbit/notificationcenter/decoder" "github.com/pkg/errors" + + "github.com/geniusrabbit/notificationcenter/v2/decoder" ) var errInvalidReturnType = errors.New("invalid return types") @@ -15,8 +16,12 @@ func ReceiverFrom(handler any) Receiver { switch h := handler.(type) { case Receiver: return h + case func() error: + return FuncReceiver(func(msg Message) error { h(); return msg.Ack() }) case func(msg Message) error: return FuncReceiver(h) + case func(ctx context.Context, msg Message) error: + return FuncReceiver(func(msg Message) error { return h(msg.Context(), msg) }) default: return ExtFuncReceiver(h) } diff --git a/redis/options.go b/redis/options.go index db916b0..2e9c730 100644 --- a/redis/options.go +++ b/redis/options.go @@ -5,9 +5,9 @@ import ( "strings" "github.com/demdxx/gocast" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/logger" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/logger" "github.com/go-redis/redis/v8" ) diff --git a/redis/options_test.go b/redis/options_test.go index 22a0bb2..fc7e64c 100644 --- a/redis/options_test.go +++ b/redis/options_test.go @@ -3,9 +3,9 @@ package redis import ( "testing" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/logger" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/logger" "github.com/go-redis/redis/v8" "github.com/stretchr/testify/assert" ) diff --git a/redis/publisher.go b/redis/publisher.go index db11a72..e63a49f 100644 --- a/redis/publisher.go +++ b/redis/publisher.go @@ -6,9 +6,9 @@ import ( "github.com/go-redis/redis/v8" "go.uber.org/multierr" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/encoder" - "github.com/geniusrabbit/notificationcenter/internal/bytebuffer" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/encoder" + "github.com/geniusrabbit/notificationcenter/v2/internal/bytebuffer" ) // Publisher for NATS queue diff --git a/redis/subscriber.go b/redis/subscriber.go index 0f20205..9d8e696 100644 --- a/redis/subscriber.go +++ b/redis/subscriber.go @@ -5,7 +5,7 @@ import ( "github.com/go-redis/redis/v8" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) // Subscriber for Redis channels diff --git a/redis/subsub_test.go b/redis/subsub_test.go index f362c88..67be6c7 100644 --- a/redis/subsub_test.go +++ b/redis/subsub_test.go @@ -8,7 +8,7 @@ import ( "time" miniredis "github.com/alicebob/miniredis/v2" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" "github.com/stretchr/testify/assert" ) diff --git a/registry.go b/registry.go index ef3f802..18acab2 100644 --- a/registry.go +++ b/registry.go @@ -102,9 +102,9 @@ func (r *Registry) Publish(ctx context.Context, name string, messages ...any) er } // Subscribe new handler on some particular subscriber interface by name -func (r *Registry) Subscribe(ctx context.Context, name string, receiver Receiver) error { +func (r *Registry) Subscribe(ctx context.Context, name string, receiver any) error { if sub := r.Subscriber(name); sub != nil { - return sub.Subscribe(ctx, receiver) + return sub.Subscribe(ctx, ReceiverFrom(receiver)) } return errors.Wrap(ErrUndefinedSubscriberInterface, name) } diff --git a/wrappers/concurrency/options.go b/wrappers/concurrency/options.go index ae05408..5a4ceef 100644 --- a/wrappers/concurrency/options.go +++ b/wrappers/concurrency/options.go @@ -1,6 +1,6 @@ package concurrency -import "github.com/demdxx/rpool" +import "github.com/demdxx/rpool/v2" // Option func type which adjust option values type Option func() rpool.Option diff --git a/wrappers/concurrency/receiver.go b/wrappers/concurrency/receiver.go index 54a92bd..b49dc86 100644 --- a/wrappers/concurrency/receiver.go +++ b/wrappers/concurrency/receiver.go @@ -1,8 +1,8 @@ package concurrency import ( - "github.com/demdxx/rpool" - nc "github.com/geniusrabbit/notificationcenter" + "github.com/demdxx/rpool/v2" + nc "github.com/geniusrabbit/notificationcenter/v2" ) type errHandlerFnk func(err error, msg nc.Message) @@ -10,7 +10,7 @@ type errHandlerFnk func(err error, msg nc.Message) type receiver struct { receiver nc.Receiver errHandler errHandlerFnk - execPool *rpool.PoolFunc + execPool *rpool.PoolFunc[nc.Message] } // WithWorkers wraps receiver in concurrent pool @@ -32,12 +32,11 @@ func (r *receiver) Receive(msg nc.Message) error { return nil } -func (r *receiver) executor(msg any) { - ncMsg := msg.(nc.Message) - err := r.receiver.Receive(ncMsg) +func (r *receiver) executor(msg nc.Message) { + err := r.receiver.Receive(msg) if err != nil { if r.errHandler != nil { - r.errHandler(err, ncMsg) + r.errHandler(err, msg) } else { panic(err) } diff --git a/wrappers/concurrency/receiver_test.go b/wrappers/concurrency/receiver_test.go index b0a2787..7282dad 100644 --- a/wrappers/concurrency/receiver_test.go +++ b/wrappers/concurrency/receiver_test.go @@ -10,8 +10,8 @@ import ( "github.com/stretchr/testify/assert" - nc "github.com/geniusrabbit/notificationcenter" - "github.com/geniusrabbit/notificationcenter/mocks" + nc "github.com/geniusrabbit/notificationcenter/v2" + "github.com/geniusrabbit/notificationcenter/v2/mocks" ) func TestConcurrency(t *testing.T) { diff --git a/wrappers/once/bigcache/checker.go b/wrappers/once/bigcache/checker.go index 128e5fa..5a80c7f 100644 --- a/wrappers/once/bigcache/checker.go +++ b/wrappers/once/bigcache/checker.go @@ -4,7 +4,7 @@ import ( "time" "github.com/allegro/bigcache" - "github.com/geniusrabbit/notificationcenter/internal/objecthash" + "github.com/geniusrabbit/notificationcenter/v2/internal/objecthash" ) // Checker provides inmemory messages test diff --git a/wrappers/once/publisher.go b/wrappers/once/publisher.go index d666ccf..96d59ee 100644 --- a/wrappers/once/publisher.go +++ b/wrappers/once/publisher.go @@ -4,7 +4,7 @@ import ( "context" "io" - nc "github.com/geniusrabbit/notificationcenter" + nc "github.com/geniusrabbit/notificationcenter/v2" ) // PublisherWrapper provides additional check before send message to the stream diff --git a/wrappers/once/publisher_test.go b/wrappers/once/publisher_test.go index 35ba855..3db5e21 100644 --- a/wrappers/once/publisher_test.go +++ b/wrappers/once/publisher_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/assert" - "github.com/geniusrabbit/notificationcenter/dummy" - "github.com/geniusrabbit/notificationcenter/wrappers/once/bigcache" + "github.com/geniusrabbit/notificationcenter/v2/dummy" + "github.com/geniusrabbit/notificationcenter/v2/wrappers/once/bigcache" ) func TestPublisher(t *testing.T) { diff --git a/wrappers/once/redis/checker.go b/wrappers/once/redis/checker.go index c371585..f499624 100644 --- a/wrappers/once/redis/checker.go +++ b/wrappers/once/redis/checker.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/geniusrabbit/notificationcenter/internal/objecthash" + "github.com/geniusrabbit/notificationcenter/v2/internal/objecthash" "github.com/go-redis/redis/v8" ) From 8a609eac195752518f0bc1ea3be5db3bcf86abc7 Mon Sep 17 00:00:00 2001 From: Dmitry Ponomarev Date: Thu, 17 Mar 2022 17:25:14 +0100 Subject: [PATCH 3/3] Up mocks --- mocks/publisher.go | 6 +++--- mocks/receiver.go | 2 +- mocks/subscriber.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mocks/publisher.go b/mocks/publisher.go index 5a1b113..f1ba038 100644 --- a/mocks/publisher.go +++ b/mocks/publisher.go @@ -36,7 +36,7 @@ func (m *MockPublisher) EXPECT() *MockPublisherMockRecorder { // Publish mocks base method func (m *MockPublisher) Publish(ctx context.Context, messages ...any) error { m.ctrl.T.Helper() - varargs := []any{ctx} + varargs := []interface{}{ctx} for _, a := range messages { varargs = append(varargs, a) } @@ -46,8 +46,8 @@ func (m *MockPublisher) Publish(ctx context.Context, messages ...any) error { } // Publish indicates an expected call of Publish -func (mr *MockPublisherMockRecorder) Publish(ctx any, messages ...any) *gomock.Call { +func (mr *MockPublisherMockRecorder) Publish(ctx interface{}, messages ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx}, messages...) + varargs := append([]interface{}{ctx}, messages...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Publish", reflect.TypeOf((*MockPublisher)(nil).Publish), varargs...) } diff --git a/mocks/receiver.go b/mocks/receiver.go index 6f9e1c6..92fbb11 100644 --- a/mocks/receiver.go +++ b/mocks/receiver.go @@ -42,7 +42,7 @@ func (m *MockReceiver) Receive(msg notificationcenter.Message) error { } // Receive indicates an expected call of Receive -func (mr *MockReceiverMockRecorder) Receive(msg any) *gomock.Call { +func (mr *MockReceiverMockRecorder) Receive(msg interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Receive", reflect.TypeOf((*MockReceiver)(nil).Receive), msg) } diff --git a/mocks/subscriber.go b/mocks/subscriber.go index aafc6d3..8799837 100644 --- a/mocks/subscriber.go +++ b/mocks/subscriber.go @@ -57,7 +57,7 @@ func (m *MockSubscriber) Subscribe(ctx context.Context, receiver notificationcen } // Subscribe indicates an expected call of Subscribe -func (mr *MockSubscriberMockRecorder) Subscribe(ctx, receiver any) *gomock.Call { +func (mr *MockSubscriberMockRecorder) Subscribe(ctx, receiver interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Subscribe", reflect.TypeOf((*MockSubscriber)(nil).Subscribe), ctx, receiver) } @@ -71,7 +71,7 @@ func (m *MockSubscriber) Listen(ctx context.Context) error { } // Listen indicates an expected call of Listen -func (mr *MockSubscriberMockRecorder) Listen(ctx any) *gomock.Call { +func (mr *MockSubscriberMockRecorder) Listen(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Listen", reflect.TypeOf((*MockSubscriber)(nil).Listen), ctx) }