From 72ec64c7810056a56ce15aebbda857add0044e9a Mon Sep 17 00:00:00 2001 From: Sophos Date: Fri, 11 May 2018 17:23:28 +0800 Subject: [PATCH] update --- Gopkg.toml | 34 ++++++++++++++++++++++++++++++++++ command.go | 8 ++------ command_test.go | 2 ++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 Gopkg.toml diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..e14bfeb --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,34 @@ + +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" + + +[[constraint]] + name = "github.com/prometheus/client_golang" + version = "0.8.0" + +[[constraint]] + name = "github.com/sony/gobreaker" + branch = "master" + +[[constraint]] + name = "github.com/stretchr/testify" + version = "1.2.1" diff --git a/command.go b/command.go index bd0201c..f8c347c 100644 --- a/command.go +++ b/command.go @@ -20,10 +20,6 @@ type command struct { var ( // errPanic is returned when goroutine panics errPanic = errors.New("command panics") - // errTooManyRequests is returned when the CB state is half open and the requests count is over the cb maxRequests - errTooManyRequests = errors.New("too many requests") - // errOpenState is returned when the CB state is open - errOpenState = errors.New("circuit breaker is open") ) // errorWithFallback process error and fallback logic, with prometheus metrics @@ -66,9 +62,9 @@ func errorToEvent(err error) string { event = "context-deadline-exceeded" case context.Canceled: event = "context-cancled" - case errTooManyRequests: + case gobreaker.ErrTooManyRequests: event = "too-many-requests" - case errOpenState: + case gobreaker.ErrOpenState: event = "circuit-open" case errPanic: event = "panic" diff --git a/command_test.go b/command_test.go index b73aadf..49ffc79 100644 --- a/command_test.go +++ b/command_test.go @@ -9,4 +9,6 @@ import ( func TestErrorToEvent(t *testing.T) { assert.Equal(t, "too-many-requests", errorToEvent(gobreaker.ErrTooManyRequests)) + assert.Equal(t, "circuit-open", errorToEvent(gobreaker.ErrOpenState)) + assert.Equal(t, "success", errorToEvent(nil)) }