Skip to content

Commit a29a5f0

Browse files
authored
Merge pull request #39 from fredbi/chore/update-linting
chore: updated & relinted
2 parents 2aab6fa + f31585d commit a29a5f0

File tree

9 files changed

+529
-480
lines changed

9 files changed

+529
-480
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/go-test.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: go test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
name: Lint
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-go@v4
12+
with:
13+
go-version: stable
14+
check-latest: true
15+
cache: true
16+
- name: golangci-lint
17+
uses: golangci/golangci-lint-action@v3
18+
with:
19+
version: latest
20+
only-new-issues: true
21+
22+
test:
23+
name: Unit tests
24+
runs-on: ${{ matrix.os }}
25+
26+
strategy:
27+
matrix:
28+
os: [ ubuntu-latest, macos-latest, windows-latest ]
29+
go_version: ['oldstable', 'stable' ]
30+
31+
steps:
32+
- name: Run unit tests
33+
uses: actions/setup-go@v4
34+
with:
35+
go-version: '${{ matrix.go_version }}'
36+
check-latest: true
37+
cache: true
38+
39+
- uses: actions/checkout@v3
40+
41+
- run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic ./...
42+
43+
- name: Upload coverage to codecov
44+
uses: codecov/codecov-action@v3
45+
with:
46+
files: './coverage-${{ matrix.os }}.${{ matrix.go_version }}.out'
47+
flags: '${{ matrix.go_version }}'
48+
os: '${{ matrix.os }}'
49+
fail_ci_if_error: false
50+
verbose: true

.golangci.yml

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,59 @@ linters-settings:
44
golint:
55
min-confidence: 0
66
gocyclo:
7-
min-complexity: 30
7+
min-complexity: 45
88
maligned:
99
suggest-new: true
1010
dupl:
11-
threshold: 100
11+
threshold: 200
1212
goconst:
1313
min-len: 2
14-
min-occurrences: 4
14+
min-occurrences: 3
15+
1516
linters:
1617
enable-all: true
1718
disable:
19+
- errname # this repo doesn't follow the convention advised by this linter
1820
- maligned
21+
- unparam
1922
- lll
23+
- gochecknoinits
2024
- gochecknoglobals
25+
- funlen
2126
- godox
2227
- gocognit
2328
- whitespace
2429
- wsl
25-
- funlen
26-
- gochecknoglobals
27-
- gochecknoinits
28-
- scopelint
2930
- wrapcheck
30-
- exhaustivestruct
31-
- exhaustive
32-
- nlreturn
3331
- testpackage
34-
- gci
35-
- gofumpt
36-
- goerr113
32+
- nlreturn
3733
- gomnd
38-
- tparallel
34+
- exhaustivestruct
35+
- goerr113
36+
- errorlint
3937
- nestif
4038
- godot
41-
- errorlint
39+
- gofumpt
4240
- paralleltest
4341
- tparallel
44-
- cyclop
45-
- errname
46-
- varnamelen
42+
- thelper
43+
- ifshort
4744
- exhaustruct
48-
- maintidx
45+
- varnamelen
46+
- gci
47+
- depguard
48+
- errchkjson
49+
- inamedparam
50+
- nonamedreturns
51+
- musttag
52+
- ireturn
53+
- forcetypeassert
54+
- cyclop
55+
# deprecated linters
56+
- deadcode
57+
- interfacer
58+
- scopelint
59+
- varcheck
60+
- structcheck
61+
- golint
62+
- nosnakecase

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# OpenAPI errors
1+
# OpenAPI errors [![Build Status](https://github.com/go-openapi/errors/actions/workflows/go-test.yml/badge.svg)](https://github.com/go-openapi/errors/actions?query=workflow%3A"go+test") [![codecov](https://codecov.io/gh/go-openapi/errors/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/errors)
22

3-
[![Build Status](https://travis-ci.org/go-openapi/errors.svg?branch=master)](https://travis-ci.org/go-openapi/errors)
4-
[![codecov](https://codecov.io/gh/go-openapi/errors/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/errors)
53
[![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
64
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/errors/master/LICENSE)
75
[![Go Reference](https://pkg.go.dev/badge/github.com/go-openapi/errors.svg)](https://pkg.go.dev/github.com/go-openapi/errors)
8-
[![GolangCI](https://golangci.com/badges/github.com/go-openapi/errors.svg)](https://golangci.com)
96
[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/errors)](https://goreportcard.com/report/github.com/go-openapi/errors)
107

118
Shared errors and error interface used throughout the various libraries found in the go-openapi toolkit.

api.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ func (a apiError) MarshalJSON() ([]byte, error) {
5555
// New creates a new API error with a code and a message
5656
func New(code int32, message string, args ...interface{}) Error {
5757
if len(args) > 0 {
58-
return &apiError{code, fmt.Sprintf(message, args...)}
58+
return &apiError{
59+
code: code,
60+
message: fmt.Sprintf(message, args...),
61+
}
62+
}
63+
return &apiError{
64+
code: code,
65+
message: message,
5966
}
60-
return &apiError{code, message}
6167
}
6268

6369
// NotFound creates a new not found error
@@ -130,10 +136,14 @@ func flattenComposite(errs *CompositeError) *CompositeError {
130136
// MethodNotAllowed creates a new method not allowed error
131137
func MethodNotAllowed(requested string, allow []string) Error {
132138
msg := fmt.Sprintf("method %s is not allowed, but [%s] are", requested, strings.Join(allow, ","))
133-
return &MethodNotAllowedError{code: http.StatusMethodNotAllowed, Allowed: allow, message: msg}
139+
return &MethodNotAllowedError{
140+
code: http.StatusMethodNotAllowed,
141+
Allowed: allow,
142+
message: msg,
143+
}
134144
}
135145

136-
// ServeError the error handler interface implementation
146+
// ServeError implements the http error handler interface
137147
func ServeError(rw http.ResponseWriter, r *http.Request, err error) {
138148
rw.Header().Set("Content-Type", "application/json")
139149
switch e := err.(type) {

api_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,37 +148,37 @@ func TestServeError(t *testing.T) {
148148

149149
func TestAPIErrors(t *testing.T) {
150150
err := New(402, "this failed %s", "yada")
151-
assert.Error(t, err)
151+
require.Error(t, err)
152152
assert.EqualValues(t, 402, err.Code())
153153
assert.EqualValues(t, "this failed yada", err.Error())
154154

155155
err = NotFound("this failed %d", 1)
156-
assert.Error(t, err)
156+
require.Error(t, err)
157157
assert.EqualValues(t, http.StatusNotFound, err.Code())
158158
assert.EqualValues(t, "this failed 1", err.Error())
159159

160160
err = NotFound("")
161-
assert.Error(t, err)
161+
require.Error(t, err)
162162
assert.EqualValues(t, http.StatusNotFound, err.Code())
163163
assert.EqualValues(t, "Not found", err.Error())
164164

165165
err = NotImplemented("not implemented")
166-
assert.Error(t, err)
166+
require.Error(t, err)
167167
assert.EqualValues(t, http.StatusNotImplemented, err.Code())
168168
assert.EqualValues(t, "not implemented", err.Error())
169169

170170
err = MethodNotAllowed("GET", []string{"POST", "PUT"})
171-
assert.Error(t, err)
171+
require.Error(t, err)
172172
assert.EqualValues(t, http.StatusMethodNotAllowed, err.Code())
173173
assert.EqualValues(t, "method GET is not allowed, but [POST,PUT] are", err.Error())
174174

175175
err = InvalidContentType("application/saml", []string{"application/json", "application/x-yaml"})
176-
assert.Error(t, err)
176+
require.Error(t, err)
177177
assert.EqualValues(t, http.StatusUnsupportedMediaType, err.Code())
178178
assert.EqualValues(t, "unsupported media type \"application/saml\", only [application/json application/x-yaml] are allowed", err.Error())
179179

180180
err = InvalidResponseFormat("application/saml", []string{"application/json", "application/x-yaml"})
181-
assert.Error(t, err)
181+
require.Error(t, err)
182182
assert.EqualValues(t, http.StatusNotAcceptable, err.Code())
183183
assert.EqualValues(t, "unsupported media type requested, only [application/json application/x-yaml] are available", err.Error())
184184
}

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
module github.com/go-openapi/errors
22

3-
go 1.14
3+
require github.com/stretchr/testify v1.6.1
44

55
require (
66
github.com/davecgh/go-spew v1.1.1 // indirect
77
github.com/kr/text v0.2.0 // indirect
88
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
9-
github.com/stretchr/testify v1.6.1
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
1010
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
1111
gopkg.in/yaml.v3 v3.0.1 // indirect
1212
)
13+
14+
go 1.19

go.sum

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
21
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
32
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
43
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
54
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
75
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
8-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
96
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
107
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
118
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
@@ -16,13 +13,9 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
1613
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1714
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
1815
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
19-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2016
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2117
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
2218
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
23-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
2419
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
25-
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c h1:grhR+C34yXImVGp7EzNk+DTIk+323eIUWOmEevy6bDo=
26-
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2720
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2821
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)