From d7f91eda78276b7534ec58e5c624fc391a7f80bf Mon Sep 17 00:00:00 2001 From: "Andrew S. Brown" Date: Mon, 30 Oct 2017 15:56:19 -0700 Subject: [PATCH 1/5] Run go vet on circleci. --- circle.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..2d896e1 --- /dev/null +++ b/circle.yml @@ -0,0 +1,3 @@ +test: + post: + - go vet ./... From eb6599853c2111b38dc00b73c8f5e662263de825 Mon Sep 17 00:00:00 2001 From: "Andrew S. Brown" Date: Mon, 30 Oct 2017 16:03:24 -0700 Subject: [PATCH 2/5] trigger build --- circle.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/circle.yml b/circle.yml index 2d896e1..8e7d380 100644 --- a/circle.yml +++ b/circle.yml @@ -1,3 +1,4 @@ test: post: - go vet ./... + From f4bbfb75f2efc1b9ed4d8d761a663b54b4842804 Mon Sep 17 00:00:00 2001 From: "Andrew S. Brown" Date: Mon, 30 Oct 2017 16:05:26 -0700 Subject: [PATCH 3/5] Use go standard test naming conventions --- normalise_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/normalise_test.go b/normalise_test.go index f489eaf..a537459 100644 --- a/normalise_test.go +++ b/normalise_test.go @@ -15,7 +15,7 @@ var ( expected = []string{"line1", "line2", "line3"} ) -func Testnormaliser(t *testing.T) { +func TestNormaliser(t *testing.T) { for i, first := range endings { for j, second := range endings { for k, suffix := range suffixes { From 126b1e523d4cfd50fc31bf8feca62716c8d106c5 Mon Sep 17 00:00:00 2001 From: "Andrew S. Brown" Date: Mon, 30 Oct 2017 16:06:36 -0700 Subject: [PATCH 4/5] Use only pointer methods for repository. go vet notes that using non-pointer methods copies the mutext lock that is a member of this class. --- repository.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/repository.go b/repository.go index 9dd8651..d4b6418 100644 --- a/repository.go +++ b/repository.go @@ -17,13 +17,13 @@ func NewSliceRepository() *SliceRepository { } } -func (repo SliceRepository) indexOfEvent(channel, id string) int { +func (repo *SliceRepository) indexOfEvent(channel, id string) int { return sort.Search(len(repo.events[channel]), func(i int) bool { return repo.events[channel][i].Id() >= id }) } -func (repo SliceRepository) Replay(channel, id string) (out chan Event) { +func (repo *SliceRepository) Replay(channel, id string) (out chan Event) { out = make(chan Event) go func() { defer close(out) From 6fc0f23cc4a72344ced8336883bdaf4439f2f9bd Mon Sep 17 00:00:00 2001 From: "Andrew S. Brown" Date: Mon, 30 Oct 2017 16:08:56 -0700 Subject: [PATCH 5/5] Fix race condition with setting checkRedirect on http client. Otherwise go test -race may report that checkRedirect is read before it is written. --- stream.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stream.go b/stream.go index 5970877..6bcdfb1 100644 --- a/stream.go +++ b/stream.go @@ -53,10 +53,14 @@ func Subscribe(url, lastEventId string) (*Stream, error) { return SubscribeWithRequest(lastEventId, req) } +var redirectingClient = &http.Client{ + CheckRedirect: checkRedirect, +} + // SubscribeWithRequest will take an http.Request to setup the stream, allowing custom headers // to be specified, authentication to be configured, etc. func SubscribeWithRequest(lastEventId string, request *http.Request) (*Stream, error) { - return SubscribeWith(lastEventId, http.DefaultClient, request) + return SubscribeWith(lastEventId, redirectingClient, request) } // SubscribeWith takes a http client and request providing customization over both headers and @@ -70,7 +74,6 @@ func SubscribeWith(lastEventId string, client *http.Client, request *http.Reques Events: make(chan Event), Errors: make(chan error), } - stream.c.CheckRedirect = checkRedirect r, err := stream.connect() if err != nil {