Skip to content

Commit

Permalink
Fixed golangci-lint reported linting issues
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
  • Loading branch information
fredbi committed Oct 21, 2018
1 parent d9664f9 commit ffa0f45
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
19 changes: 19 additions & 0 deletions .golangci.yml
@@ -0,0 +1,19 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 30
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 4
linters:
enable-all: true
disable:
- maligned
- lll
10 changes: 5 additions & 5 deletions api.go
Expand Up @@ -134,26 +134,26 @@ func ServeError(rw http.ResponseWriter, r *http.Request, err error) {
rw.Header().Add("Allow", strings.Join(err.(*MethodNotAllowedError).Allowed, ","))
rw.WriteHeader(asHTTPCode(int(e.Code())))
if r == nil || r.Method != head {
rw.Write(errorAsJSON(e))
_, _ = rw.Write(errorAsJSON(e))
}
case Error:
value := reflect.ValueOf(e)
if value.Kind() == reflect.Ptr && value.IsNil() {
rw.WriteHeader(http.StatusInternalServerError)
rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error")))
_, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error")))
return
}
rw.WriteHeader(asHTTPCode(int(e.Code())))
if r == nil || r.Method != head {
rw.Write(errorAsJSON(e))
_, _ = rw.Write(errorAsJSON(e))
}
case nil:
rw.WriteHeader(http.StatusInternalServerError)
rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error")))
_, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error")))
default:
rw.WriteHeader(http.StatusInternalServerError)
if r == nil || r.Method != head {
rw.Write(errorAsJSON(New(http.StatusInternalServerError, err.Error())))
_, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, err.Error())))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions headers.go
Expand Up @@ -54,7 +54,7 @@ const (

// InvalidContentType error for an invalid content type
func InvalidContentType(value string, allowed []string) *Validation {
var values []interface{}
values := make([]interface{}, 0, len(allowed))
for _, v := range allowed {
values = append(values, v)
}
Expand All @@ -70,7 +70,7 @@ func InvalidContentType(value string, allowed []string) *Validation {

// InvalidResponseFormat error for an unacceptable response format request
func InvalidResponseFormat(value string, allowed []string) *Validation {
var values []interface{}
values := make([]interface{}, 0, len(allowed))
for _, v := range allowed {
values = append(values, v)
}
Expand Down
4 changes: 2 additions & 2 deletions schema_test.go
Expand Up @@ -293,10 +293,10 @@ func TestSchemaErrors(t *testing.T) {
assert.EqualValues(t, CompositeErrorCode, err2.Code())
assert.Equal(t, "validation failure list", err2.Error())

err2 = CompositeValidationError(fmt.Errorf("First error"), fmt.Errorf("Second error"))
err2 = CompositeValidationError(fmt.Errorf("first error"), fmt.Errorf("second error"))
assert.Error(t, err2)
assert.EqualValues(t, CompositeErrorCode, err2.Code())
assert.Equal(t, "validation failure list:\nFirst error\nSecond error", err2.Error())
assert.Equal(t, "validation failure list:\nfirst error\nsecond error", err2.Error())

//func MultipleOfMustBePositive(name, in string, factor interface{}) *Validation {
err = MultipleOfMustBePositive("path", "body", float64(-10))
Expand Down

0 comments on commit ffa0f45

Please sign in to comment.