Skip to content

Commit

Permalink
Fix lint warnings
Browse files Browse the repository at this point in the history
This commit fixes most of warnings, but not all of them.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
  • Loading branch information
kzys committed Jan 29, 2022
1 parent 23bff48 commit 413d78f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
linters-settings:
govet:
check-shadowing: true
# Using err repeatedly considered as shadowing.
check-shadowing: false
golint:
min-confidence: 0
gocyclo:
Expand Down
2 changes: 2 additions & 0 deletions bytestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func ByteStreamConsumer(opts ...byteStreamOpt) Consumer {
close = cl.Close
}
}
//nolint:errcheck // closing a reader wouldn't fail.
defer close()

if wrtr, ok := data.(io.Writer); ok {
Expand Down Expand Up @@ -114,6 +115,7 @@ func ByteStreamProducer(opts ...byteStreamOpt) Producer {
close = cl.Close
}
}
//nolint:errcheck // TODO: closing a writer would fail.
defer close()

if rc, ok := data.(io.ReadCloser); ok {
Expand Down
5 changes: 4 additions & 1 deletion client/keepalive.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func (d *drainingReadCloser) Read(p []byte) (n int, err error) {
func (d *drainingReadCloser) Close() error {
// drain buffer
if atomic.LoadUint32(&d.seenEOF) != 1 {
//#nosec
// If the reader side (a HTTP server) is misbehaving, it still may send
// some bytes, but the closer ignores them to keep the underling
// connection open.
//nolint:errcheck
io.Copy(ioutil.Discard, d.rdr)
}
return d.rdr.Close()
Expand Down
21 changes: 13 additions & 8 deletions client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ func (r *request) BuildHTTP(mediaType, basePath string, producers map[string]run
func escapeQuotes(s string) string {
return strings.NewReplacer("\\", "\\\\", `"`, "\\\"").Replace(s)
}

func logClose(err error, pw *io.PipeWriter) {
log.Println(err)
closeErr := pw.CloseWithError(err)
if closeErr != nil {
log.Println(closeErr)
}
}

func (r *request) buildHTTP(mediaType, basePath string, producers map[string]runtime.Producer, registry strfmt.Registry, auth runtime.ClientAuthInfoWriter) (*http.Request, error) {
// build the data
if err := r.writer.WriteToRequest(r, registry); err != nil {
Expand Down Expand Up @@ -137,8 +146,7 @@ func (r *request) buildHTTP(mediaType, basePath string, producers map[string]run
for fn, v := range r.formFields {
for _, vi := range v {
if err := mp.WriteField(fn, vi); err != nil {
pw.CloseWithError(err)
log.Println(err)
logClose(err, pw)
return
}
}
Expand All @@ -157,8 +165,7 @@ func (r *request) buildHTTP(mediaType, basePath string, producers map[string]run
buf := make([]byte, 512)
size, err := fi.Read(buf)
if err != nil {
_ = pw.CloseWithError(err)
log.Println(err)
logClose(err, pw)
return
}
fileContentType := http.DetectContentType(buf)
Expand All @@ -173,13 +180,11 @@ func (r *request) buildHTTP(mediaType, basePath string, producers map[string]run

wrtr, err := mp.CreatePart(h)
if err != nil {
pw.CloseWithError(err)
log.Println(err)
logClose(err, pw)
return
}
if _, err := io.Copy(wrtr, newFi); err != nil {
pw.CloseWithError(err)
log.Println(err)
logClose(err, pw)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func HasBody(r *http.Request) bool {
return true
}

if r.Header.Get(http.CanonicalHeaderKey("content-length")) != "" {
if r.Header.Get("content-length") != "" {
// in this case, no Transfer-Encoding should be present
// we have a header set but it was explicitly set to 0, so we assume no body
return false
Expand Down
1 change: 0 additions & 1 deletion text.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TextConsumer() Consumer {

// If the buffer is empty, no need to unmarshal it, which causes a panic.
if len(b) == 0 {
data = ""
return nil
}

Expand Down

0 comments on commit 413d78f

Please sign in to comment.