Skip to content

Commit 7a7ff1b

Browse files
authored
Merge pull request #18 from fredbi/golangci-linting
Fixed golangci-lint reported linting issues
2 parents d9664f9 + ffa0f45 commit 7a7ff1b

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

.golangci.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
linters-settings:
2+
govet:
3+
check-shadowing: true
4+
golint:
5+
min-confidence: 0
6+
gocyclo:
7+
min-complexity: 30
8+
maligned:
9+
suggest-new: true
10+
dupl:
11+
threshold: 100
12+
goconst:
13+
min-len: 2
14+
min-occurrences: 4
15+
linters:
16+
enable-all: true
17+
disable:
18+
- maligned
19+
- lll

api.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,26 @@ func ServeError(rw http.ResponseWriter, r *http.Request, err error) {
134134
rw.Header().Add("Allow", strings.Join(err.(*MethodNotAllowedError).Allowed, ","))
135135
rw.WriteHeader(asHTTPCode(int(e.Code())))
136136
if r == nil || r.Method != head {
137-
rw.Write(errorAsJSON(e))
137+
_, _ = rw.Write(errorAsJSON(e))
138138
}
139139
case Error:
140140
value := reflect.ValueOf(e)
141141
if value.Kind() == reflect.Ptr && value.IsNil() {
142142
rw.WriteHeader(http.StatusInternalServerError)
143-
rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error")))
143+
_, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error")))
144144
return
145145
}
146146
rw.WriteHeader(asHTTPCode(int(e.Code())))
147147
if r == nil || r.Method != head {
148-
rw.Write(errorAsJSON(e))
148+
_, _ = rw.Write(errorAsJSON(e))
149149
}
150150
case nil:
151151
rw.WriteHeader(http.StatusInternalServerError)
152-
rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error")))
152+
_, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error")))
153153
default:
154154
rw.WriteHeader(http.StatusInternalServerError)
155155
if r == nil || r.Method != head {
156-
rw.Write(errorAsJSON(New(http.StatusInternalServerError, err.Error())))
156+
_, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, err.Error())))
157157
}
158158
}
159159
}

headers.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const (
5454

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

7171
// InvalidResponseFormat error for an unacceptable response format request
7272
func InvalidResponseFormat(value string, allowed []string) *Validation {
73-
var values []interface{}
73+
values := make([]interface{}, 0, len(allowed))
7474
for _, v := range allowed {
7575
values = append(values, v)
7676
}

schema_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ func TestSchemaErrors(t *testing.T) {
293293
assert.EqualValues(t, CompositeErrorCode, err2.Code())
294294
assert.Equal(t, "validation failure list", err2.Error())
295295

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

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

0 commit comments

Comments
 (0)