From f058e101b9d9653563cfc7326c7522b43d21fd15 Mon Sep 17 00:00:00 2001 From: geek Date: Sun, 14 Jun 2020 19:11:36 -0500 Subject: [PATCH] Add travis and make --- .travis.yml | 13 +++++++++++ Makefile | 10 ++++++++ README => README.md | 6 ----- herrors.go | 56 +++++++++++++++++++++++++++++++++------------ herrors_test.go | 2 +- 5 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 .travis.yml create mode 100644 Makefile rename README => README.md (97%) diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..83ac93f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: go +go_import_path: github.com/geek/herrors + +go: + - 1.14.x + - tip + +env: + global: + - GO111MODULE=on + +script: + - make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..00f7054 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +PKG := github.com/geek/herrors + +fmt: + @test -z "$(shell gofmt -s -l -d -e ./ | tee /dev/stderr)" + +vet: + go vet $(PKG) + +test: vet fmt + go test $(PKG) diff --git a/README b/README.md similarity index 97% rename from README rename to README.md index 1bb8af5..eb9b786 100644 --- a/README +++ b/README.md @@ -34,12 +34,6 @@ func handler(w http.ResponseWriter, r *http.Request) { ## Usage -The following errors are available - -```go - -``` - #### func New ```go diff --git a/herrors.go b/herrors.go index f5ea97f..10675df 100644 --- a/herrors.go +++ b/herrors.go @@ -6,21 +6,47 @@ import ( ) var ( - ErrBadRequest = New(http.StatusBadRequest) - ErrUnauthorized = New(http.StatusUnauthorized) - ErrPaymentRequired = New(http.StatusPaymentRequired) - ErrForbidden = New(http.StatusForbidden) - ErrNotFound = New(http.StatusNotFound) - ErrMethodNotAllowed = New(http.StatusMethodNotAllowed) - ErrNotAcceptable = New(http.StatusNotAcceptable) - ErrProxyAuthRequired = New(http.StatusProxyAuthRequired) - ErrRequestTimeout = New(http.StatusRequestTimeout) - ErrConflict = New(http.StatusConflict) - ErrResourceGone = New(http.StatusGone) - ErrLengthRequired = New(http.StatusLengthRequired) - ErrPreconditionFailed = New(http.StatusPreconditionFailed) - - ErrInternalServer = New(http.StatusInternalServerError) + // 4xx errors + ErrBadRequest = New(http.StatusBadRequest) + ErrUnauthorized = New(http.StatusUnauthorized) + ErrPaymentRequired = New(http.StatusPaymentRequired) + ErrForbidden = New(http.StatusForbidden) + ErrNotFound = New(http.StatusNotFound) + ErrMethodNotAllowed = New(http.StatusMethodNotAllowed) + ErrNotAcceptable = New(http.StatusNotAcceptable) + ErrProxyAuthRequired = New(http.StatusProxyAuthRequired) + ErrRequestTimeout = New(http.StatusRequestTimeout) + ErrConflict = New(http.StatusConflict) + ErrResourceGone = New(http.StatusGone) + ErrLengthRequired = New(http.StatusLengthRequired) + ErrPreconditionFailed = New(http.StatusPreconditionFailed) + ErrEntityTooLarge = New(http.StatusRequestEntityTooLarge) + ErrURITooLong = New(http.StatusRequestURITooLong) + ErrUnsupportedMediaType = New(http.StatusUnsupportedMediaType) + ErrRangeNotSatisfiable = New(http.StatusRequestedRangeNotSatisfiable) + ErrExpectationFailed = New(http.StatusExpectationFailed) + ErrMisdirectedRequest = New(http.StatusMisdirectedRequest) + ErrUnprocessableEntity = New(http.StatusUnprocessableEntity) + ErrLocked = New(http.StatusLocked) + ErrFailedDependency = New(http.StatusFailedDependency) + ErrTooEarly = New(http.StatusTooEarly) + ErrPreconditionRequired = New(http.StatusPreconditionRequired) + ErrTooManyRequests = New(http.StatusTooManyRequests) + ErrHeaderFieldsTooLarge = New(http.StatusRequestHeaderFieldsTooLarge) + ErrIllegal = New(http.StatusUnavailableForLegalReasons) + + // 5xx errors + ErrInternalServer = New(http.StatusInternalServerError) + ErrNotImplemented = New(http.StatusNotImplemented) + ErrBadGateway = New(http.StatusBadGateway) + ErrServiceUnavailable = New(http.StatusServiceUnavailable) + ErrGatewayTimeout = New(http.StatusGatewayTimeout) + ErrHTTPVersionNotSupported = New(http.StatusHTTPVersionNotSupported) + ErrVariantAlsoNegotiates = New(http.StatusVariantAlsoNegotiates) + ErrInsufficientStorage = New(http.StatusInsufficientStorage) + ErrLoopDetected = New(http.StatusLoopDetected) + ErrNotExtended = New(http.StatusNotExtended) + ErrNetworkAuthenticationRequired = New(http.StatusNetworkAuthenticationRequired) ) // New constructs an ErrHttp error with the code and message populated diff --git a/herrors_test.go b/herrors_test.go index a95e14c..9ee1b6a 100644 --- a/herrors_test.go +++ b/herrors_test.go @@ -75,7 +75,7 @@ func TestErrorWrapUnwrap(t *testing.T) { } } -func TestfmtErrorfWrap(t *testing.T) { +func TestFmtErrorfWrap(t *testing.T) { w := fmt.Errorf("foo %w", ErrBadRequest) type hasCode interface {