[#148] Fix lint errors

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-06-03 13:35:27 +03:00 committed by Alex Vanin
parent 562c7e994c
commit b0b724393a

View file

@ -107,7 +107,7 @@ func NewReader(r io.Reader, boundary string) *Reader {
// underlying Reader once an error has been seen. (the io.Reader // underlying Reader once an error has been seen. (the io.Reader
// interface's contract promises nothing about the return values of // interface's contract promises nothing about the return values of
// Read calls after an error, yet this package does do multiple Reads // Read calls after an error, yet this package does do multiple Reads
// after error) // after error).
type stickyErrorReader struct { type stickyErrorReader struct {
r io.Reader r io.Reader
err error err error
@ -142,11 +142,11 @@ func newPart(mr *Reader, rawPart bool) (*Part, error) {
return bp, nil return bp, nil
} }
func (bp *Part) populateHeaders() error { func (p *Part) populateHeaders() error {
r := textproto.NewReader(bp.mr.bufReader) r := textproto.NewReader(p.mr.bufReader)
header, err := r.ReadMIMEHeader() header, err := r.ReadMIMEHeader()
if err == nil { if err == nil {
bp.Header = header p.Header = header
} }
return err return err
} }
@ -278,7 +278,7 @@ func matchAfterPrefix(buf, prefix []byte, readErr error) int {
} }
func (p *Part) Close() error { func (p *Part) Close() error {
io.Copy(io.Discard, p) _, _ = io.Copy(io.Discard, p)
return nil return nil
} }
@ -378,37 +378,37 @@ func (r *Reader) nextPart(rawPart bool) (*Part, error) {
// isFinalBoundary reports whether line is the final boundary line // isFinalBoundary reports whether line is the final boundary line
// indicating that all parts are over. // indicating that all parts are over.
// It matches `^--boundary--[ \t]*(\r\n)?$` // It matches `^--boundary--[ \t]*(\r\n)?$`.
func (mr *Reader) isFinalBoundary(line []byte) bool { func (r *Reader) isFinalBoundary(line []byte) bool {
if !bytes.HasPrefix(line, mr.dashBoundaryDash) { if !bytes.HasPrefix(line, r.dashBoundaryDash) {
return false return false
} }
rest := line[len(mr.dashBoundaryDash):] rest := line[len(r.dashBoundaryDash):]
rest = skipLWSPChar(rest) rest = skipLWSPChar(rest)
return len(rest) == 0 || bytes.Equal(rest, mr.nl) return len(rest) == 0 || bytes.Equal(rest, r.nl)
} }
func (mr *Reader) isBoundaryDelimiterLine(line []byte) (ret bool) { func (r *Reader) isBoundaryDelimiterLine(line []byte) (ret bool) {
// https://tools.ietf.org/html/rfc2046#section-5.1 // https://tools.ietf.org/html/rfc2046#section-5.1
// The boundary delimiter line is then defined as a line // The boundary delimiter line is then defined as a line
// consisting entirely of two hyphen characters ("-", // consisting entirely of two hyphen characters ("-",
// decimal value 45) followed by the boundary parameter // decimal value 45) followed by the boundary parameter
// value from the Content-Type header field, optional linear // value from the Content-Type header field, optional linear
// whitespace, and a terminating CRLF. // whitespace, and a terminating CRLF.
if !bytes.HasPrefix(line, mr.dashBoundary) { if !bytes.HasPrefix(line, r.dashBoundary) {
return false return false
} }
rest := line[len(mr.dashBoundary):] rest := line[len(r.dashBoundary):]
rest = skipLWSPChar(rest) rest = skipLWSPChar(rest)
// On the first part, see our lines are ending in \n instead of \r\n // On the first part, see our lines are ending in \n instead of \r\n
// and switch into that mode if so. This is a violation of the spec, // and switch into that mode if so. This is a violation of the spec,
// but occurs in practice. // but occurs in practice.
if mr.partsRead == 0 && len(rest) == 1 && rest[0] == '\n' { if r.partsRead == 0 && len(rest) == 1 && rest[0] == '\n' {
mr.nl = mr.nl[1:] r.nl = r.nl[1:]
mr.nlDashBoundary = mr.nlDashBoundary[1:] r.nlDashBoundary = r.nlDashBoundary[1:]
} }
return bytes.Equal(rest, mr.nl) return bytes.Equal(rest, r.nl)
} }
// skipLWSPChar returns b with leading spaces and tabs removed. // skipLWSPChar returns b with leading spaces and tabs removed.