Skip to content

Commit 8941eac

Browse files
committed
chore(lint): updated linters, relinted code
Signed-off-by: Frédéric BIDON <[email protected]>
1 parent 976f770 commit 8941eac

21 files changed

+426
-421
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ linters:
2323
- nestif
2424
- nilerr # nilerr crashes on this repo
2525
- nlreturn
26+
- noinlineerr
2627
- nonamedreturns
2728
- paralleltest
29+
- recvcheck
2830
- testpackage
2931
- thelper
3032
- tparallel
@@ -33,6 +35,7 @@ linters:
3335
- whitespace
3436
- wrapcheck
3537
- wsl
38+
- wsl_v5
3639
settings:
3740
dupl:
3841
threshold: 200

client/request.go

Lines changed: 147 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,11 @@ import (
3030
"strings"
3131
"time"
3232

33-
"github.com/go-openapi/strfmt"
34-
3533
"github.com/go-openapi/runtime"
34+
"github.com/go-openapi/strfmt"
3635
)
3736

38-
// NewRequest creates a new swagger http client request
39-
func newRequest(method, pathPattern string, writer runtime.ClientRequestWriter) *request {
40-
return &request{
41-
pathPattern: pathPattern,
42-
method: method,
43-
writer: writer,
44-
header: make(http.Header),
45-
query: make(url.Values),
46-
timeout: DefaultTimeout,
47-
getBody: getRequestBuffer,
48-
}
49-
}
37+
var _ runtime.ClientRequest = new(request) // ensure compliance to the interface
5038

5139
// Request represents a swagger client request.
5240
//
@@ -67,40 +55,156 @@ type request struct {
6755
query url.Values
6856
formFields url.Values
6957
fileFields map[string][]runtime.NamedReadCloser
70-
payload interface{}
58+
payload any
7159
timeout time.Duration
7260
buf *bytes.Buffer
7361

7462
getBody func(r *request) []byte
7563
}
7664

77-
var (
78-
// ensure interface compliance
79-
_ runtime.ClientRequest = new(request)
80-
)
81-
82-
func (r *request) isMultipart(mediaType string) bool {
83-
if len(r.fileFields) > 0 {
84-
return true
65+
// NewRequest creates a new swagger http client request
66+
func newRequest(method, pathPattern string, writer runtime.ClientRequestWriter) *request {
67+
return &request{
68+
pathPattern: pathPattern,
69+
method: method,
70+
writer: writer,
71+
header: make(http.Header),
72+
query: make(url.Values),
73+
timeout: DefaultTimeout,
74+
getBody: getRequestBuffer,
8575
}
86-
87-
return runtime.MultipartFormMime == mediaType
8876
}
8977

9078
// BuildHTTP creates a new http request based on the data from the params
9179
func (r *request) BuildHTTP(mediaType, basePath string, producers map[string]runtime.Producer, registry strfmt.Registry) (*http.Request, error) {
9280
return r.buildHTTP(mediaType, basePath, producers, registry, nil)
9381
}
94-
func escapeQuotes(s string) string {
95-
return strings.NewReplacer("\\", "\\\\", `"`, "\\\"").Replace(s)
82+
83+
func (r *request) GetMethod() string {
84+
return r.method
9685
}
9786

98-
func logClose(err error, pw *io.PipeWriter) {
99-
log.Println(err)
100-
closeErr := pw.CloseWithError(err)
101-
if closeErr != nil {
102-
log.Println(closeErr)
87+
func (r *request) GetPath() string {
88+
path := r.pathPattern
89+
for k, v := range r.pathParams {
90+
path = strings.ReplaceAll(path, "{"+k+"}", v)
91+
}
92+
return path
93+
}
94+
95+
func (r *request) GetBody() []byte {
96+
return r.getBody(r)
97+
}
98+
99+
// SetHeaderParam adds a header param to the request
100+
// when there is only 1 value provided for the varargs, it will set it.
101+
// when there are several values provided for the varargs it will add it (no overriding)
102+
func (r *request) SetHeaderParam(name string, values ...string) error {
103+
if r.header == nil {
104+
r.header = make(http.Header)
105+
}
106+
r.header[http.CanonicalHeaderKey(name)] = values
107+
return nil
108+
}
109+
110+
// GetHeaderParams returns the all headers currently set for the request
111+
func (r *request) GetHeaderParams() http.Header {
112+
return r.header
113+
}
114+
115+
// SetQueryParam adds a query param to the request
116+
// when there is only 1 value provided for the varargs, it will set it.
117+
// when there are several values provided for the varargs it will add it (no overriding)
118+
func (r *request) SetQueryParam(name string, values ...string) error {
119+
if r.query == nil {
120+
r.query = make(url.Values)
121+
}
122+
r.query[name] = values
123+
return nil
124+
}
125+
126+
// GetQueryParams returns a copy of all query params currently set for the request
127+
func (r *request) GetQueryParams() url.Values {
128+
var result = make(url.Values)
129+
for key, value := range r.query {
130+
result[key] = append([]string{}, value...)
131+
}
132+
return result
133+
}
134+
135+
// SetFormParam adds a forn param to the request
136+
// when there is only 1 value provided for the varargs, it will set it.
137+
// when there are several values provided for the varargs it will add it (no overriding)
138+
func (r *request) SetFormParam(name string, values ...string) error {
139+
if r.formFields == nil {
140+
r.formFields = make(url.Values)
141+
}
142+
r.formFields[name] = values
143+
return nil
144+
}
145+
146+
// SetPathParam adds a path param to the request
147+
func (r *request) SetPathParam(name string, value string) error {
148+
if r.pathParams == nil {
149+
r.pathParams = make(map[string]string)
150+
}
151+
152+
r.pathParams[name] = value
153+
return nil
154+
}
155+
156+
// SetFileParam adds a file param to the request
157+
func (r *request) SetFileParam(name string, files ...runtime.NamedReadCloser) error {
158+
for _, file := range files {
159+
if actualFile, ok := file.(*os.File); ok {
160+
fi, err := os.Stat(actualFile.Name())
161+
if err != nil {
162+
return err
163+
}
164+
if fi.IsDir() {
165+
return fmt.Errorf("%q is a directory, only files are supported", file.Name())
166+
}
167+
}
168+
}
169+
170+
if r.fileFields == nil {
171+
r.fileFields = make(map[string][]runtime.NamedReadCloser)
103172
}
173+
if r.formFields == nil {
174+
r.formFields = make(url.Values)
175+
}
176+
177+
r.fileFields[name] = files
178+
return nil
179+
}
180+
181+
func (r *request) GetFileParam() map[string][]runtime.NamedReadCloser {
182+
return r.fileFields
183+
}
184+
185+
// SetBodyParam sets a body parameter on the request.
186+
// This does not yet serialze the object, this happens as late as possible.
187+
func (r *request) SetBodyParam(payload any) error {
188+
r.payload = payload
189+
return nil
190+
}
191+
192+
func (r *request) GetBodyParam() any {
193+
return r.payload
194+
}
195+
196+
// SetTimeout sets the timeout for a request
197+
func (r *request) SetTimeout(timeout time.Duration) error {
198+
r.timeout = timeout
199+
return nil
200+
}
201+
202+
func (r *request) isMultipart(mediaType string) bool {
203+
if len(r.fileFields) > 0 {
204+
return true
205+
}
206+
207+
return runtime.MultipartFormMime == mediaType
104208
}
105209

106210
func (r *request) buildHTTP(mediaType, basePath string, producers map[string]runtime.Producer, registry strfmt.Registry, auth runtime.ClientAuthInfoWriter) (*http.Request, error) { //nolint:gocyclo,maintidx
@@ -349,27 +453,8 @@ DoneChoosingBodySource:
349453
return req, nil
350454
}
351455

352-
func mangleContentType(mediaType, boundary string) string {
353-
if strings.ToLower(mediaType) == runtime.URLencodedFormMime {
354-
return fmt.Sprintf("%s; boundary=%s", mediaType, boundary)
355-
}
356-
return "multipart/form-data; boundary=" + boundary
357-
}
358-
359-
func (r *request) GetMethod() string {
360-
return r.method
361-
}
362-
363-
func (r *request) GetPath() string {
364-
path := r.pathPattern
365-
for k, v := range r.pathParams {
366-
path = strings.ReplaceAll(path, "{"+k+"}", v)
367-
}
368-
return path
369-
}
370-
371-
func (r *request) GetBody() []byte {
372-
return r.getBody(r)
456+
func escapeQuotes(s string) string {
457+
return strings.NewReplacer("\\", "\\\\", `"`, "\\\"").Replace(s)
373458
}
374459

375460
func getRequestBuffer(r *request) []byte {
@@ -379,105 +464,17 @@ func getRequestBuffer(r *request) []byte {
379464
return r.buf.Bytes()
380465
}
381466

382-
// SetHeaderParam adds a header param to the request
383-
// when there is only 1 value provided for the varargs, it will set it.
384-
// when there are several values provided for the varargs it will add it (no overriding)
385-
func (r *request) SetHeaderParam(name string, values ...string) error {
386-
if r.header == nil {
387-
r.header = make(http.Header)
388-
}
389-
r.header[http.CanonicalHeaderKey(name)] = values
390-
return nil
391-
}
392-
393-
// GetHeaderParams returns the all headers currently set for the request
394-
func (r *request) GetHeaderParams() http.Header {
395-
return r.header
396-
}
397-
398-
// SetQueryParam adds a query param to the request
399-
// when there is only 1 value provided for the varargs, it will set it.
400-
// when there are several values provided for the varargs it will add it (no overriding)
401-
func (r *request) SetQueryParam(name string, values ...string) error {
402-
if r.query == nil {
403-
r.query = make(url.Values)
404-
}
405-
r.query[name] = values
406-
return nil
407-
}
408-
409-
// GetQueryParams returns a copy of all query params currently set for the request
410-
func (r *request) GetQueryParams() url.Values {
411-
var result = make(url.Values)
412-
for key, value := range r.query {
413-
result[key] = append([]string{}, value...)
414-
}
415-
return result
416-
}
417-
418-
// SetFormParam adds a forn param to the request
419-
// when there is only 1 value provided for the varargs, it will set it.
420-
// when there are several values provided for the varargs it will add it (no overriding)
421-
func (r *request) SetFormParam(name string, values ...string) error {
422-
if r.formFields == nil {
423-
r.formFields = make(url.Values)
424-
}
425-
r.formFields[name] = values
426-
return nil
427-
}
428-
429-
// SetPathParam adds a path param to the request
430-
func (r *request) SetPathParam(name string, value string) error {
431-
if r.pathParams == nil {
432-
r.pathParams = make(map[string]string)
467+
func logClose(err error, pw *io.PipeWriter) {
468+
log.Println(err)
469+
closeErr := pw.CloseWithError(err)
470+
if closeErr != nil {
471+
log.Println(closeErr)
433472
}
434-
435-
r.pathParams[name] = value
436-
return nil
437473
}
438474

439-
// SetFileParam adds a file param to the request
440-
func (r *request) SetFileParam(name string, files ...runtime.NamedReadCloser) error {
441-
for _, file := range files {
442-
if actualFile, ok := file.(*os.File); ok {
443-
fi, err := os.Stat(actualFile.Name())
444-
if err != nil {
445-
return err
446-
}
447-
if fi.IsDir() {
448-
return fmt.Errorf("%q is a directory, only files are supported", file.Name())
449-
}
450-
}
451-
}
452-
453-
if r.fileFields == nil {
454-
r.fileFields = make(map[string][]runtime.NamedReadCloser)
455-
}
456-
if r.formFields == nil {
457-
r.formFields = make(url.Values)
475+
func mangleContentType(mediaType, boundary string) string {
476+
if strings.ToLower(mediaType) == runtime.URLencodedFormMime {
477+
return fmt.Sprintf("%s; boundary=%s", mediaType, boundary)
458478
}
459-
460-
r.fileFields[name] = files
461-
return nil
462-
}
463-
464-
func (r *request) GetFileParam() map[string][]runtime.NamedReadCloser {
465-
return r.fileFields
466-
}
467-
468-
// SetBodyParam sets a body parameter on the request.
469-
// This does not yet serialze the object, this happens as late as possible.
470-
func (r *request) SetBodyParam(payload interface{}) error {
471-
r.payload = payload
472-
return nil
473-
}
474-
475-
func (r *request) GetBodyParam() interface{} {
476-
return r.payload
477-
}
478-
479-
// SetTimeout sets the timeout for a request
480-
func (r *request) SetTimeout(timeout time.Duration) error {
481-
r.timeout = timeout
482-
return nil
479+
return "multipart/form-data; boundary=" + boundary
483480
}

0 commit comments

Comments
 (0)