Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Fix linting warnings/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vcabbage committed Feb 17, 2018
1 parent 9c101f5 commit 3ecab7c
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 118 deletions.
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (c *Client) NewSession() (*Session, error) {

begin, ok := fr.body.(*performBegin)
if !ok {
s.Close() // deallocate session on error
_ = s.Close() // deallocate session on error
return nil, errorErrorf("unexpected begin response: %+v", fr.body)
}

Expand Down Expand Up @@ -782,7 +782,7 @@ func newLink(s *Session, r *Receiver, opts []LinkOption) (*link, error) {
// default to a more reasonable max and allow users to
// change via LinkOption
l.peerMaxMessageSize = maxSliceLen
if resp.MaxMessageSize != 0 && resp.MaxMessageSize < uint64(l.peerMaxMessageSize) {
if resp.MaxMessageSize != 0 && resp.MaxMessageSize < l.peerMaxMessageSize {
l.peerMaxMessageSize = resp.MaxMessageSize
}

Expand Down Expand Up @@ -1274,7 +1274,7 @@ func (r *Receiver) Receive(ctx context.Context) (*Message, error) {
messageSize += len(fr.Payload)
if messageSize > maxMessageSize {
// TODO: send error
r.Close()
_ = r.Close()
return nil, errorErrorf("received message larger than max size of ")
}

Expand Down
16 changes: 8 additions & 8 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (c *conn) start() error {
// check if err occurred
if c.err != nil {
close(c.txDone) // close here since connWriter hasn't been started yet
c.Close()
_ = c.Close()
return c.err
}

Expand Down Expand Up @@ -429,7 +429,7 @@ func (c *conn) connReader() {
// need to read more if buf doesn't contain the complete frame
// or there's not enough in buf to parse the header
if frameInProgress || buf.len() < frameHeaderSize {
c.net.SetReadDeadline(time.Now().Add(c.idleTimeout))
_ = c.net.SetReadDeadline(time.Now().Add(c.idleTimeout))
err := buf.readFromOnce(c.net)
if err != nil {
select {
Expand Down Expand Up @@ -577,7 +577,7 @@ func (c *conn) connWriter() {
// connection complete
case <-c.done:
// send close
c.writeFrame(frame{
_ = c.writeFrame(frame{
type_: frameTypeAMQP,
body: &performClose{},
})
Expand All @@ -590,7 +590,7 @@ func (c *conn) connWriter() {
// by connWriter after initial negotiation.
func (c *conn) writeFrame(fr frame) error {
if c.connectTimeout != 0 {
c.net.SetWriteDeadline(time.Now().Add(c.connectTimeout))
_ = c.net.SetWriteDeadline(time.Now().Add(c.connectTimeout))
}

// writeFrame into txBuf
Expand All @@ -614,7 +614,7 @@ func (c *conn) writeFrame(fr frame) error {
// network
func (c *conn) writeProtoHeader(pID protoID) error {
if c.connectTimeout != 0 {
c.net.SetWriteDeadline(time.Now().Add(c.connectTimeout))
_ = c.net.SetWriteDeadline(time.Now().Add(c.connectTimeout))
}
_, err := c.net.Write([]byte{'A', 'M', 'Q', 'P', byte(pID), 1, 0, 0})
return err
Expand Down Expand Up @@ -722,12 +722,12 @@ func (c *conn) startTLS() stateFunc {

// this function will be executed by connReader
c.connReaderRun <- func() {
c.net.SetReadDeadline(time.Time{}) // clear timeout
_ = c.net.SetReadDeadline(time.Time{}) // clear timeout

// wrap existing net.Conn and perform TLS handshake
tlsConn := tls.Client(c.net, c.tlsConfig)
if c.connectTimeout != 0 {
tlsConn.SetWriteDeadline(time.Now().Add(c.connectTimeout))
_ = tlsConn.SetWriteDeadline(time.Now().Add(c.connectTimeout))
}
c.err = tlsConn.Handshake()

Expand All @@ -739,7 +739,7 @@ func (c *conn) startTLS() stateFunc {
}

// set deadline to interrupt connReader
c.net.SetReadDeadline(time.Time{}.Add(1))
_ = c.net.SetReadDeadline(time.Time{}.Add(1))

<-done

Expand Down
89 changes: 46 additions & 43 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func unmarshalComposite(r *buffer, type_ amqpType, fields ...unmarshalField) err
}

// Unmarshal each of the received fields.
err := unmarshal(r, field.field)
err = unmarshal(r, field.field)
if err != nil {
return errorWrapf(err, "unmarshaling field %d", i)
}
Expand Down Expand Up @@ -406,8 +406,6 @@ type unmarshalField struct {
type nullHandler func() error

// readCompositeHeader reads and consumes the composite header from r.
//
// If the composite is null, errNull will be returned.
func readCompositeHeader(r *buffer) (_ amqpType, fields int, _ error) {
type_, err := r.readType()
if err != nil {
Expand All @@ -426,57 +424,57 @@ func readCompositeHeader(r *buffer) (_ amqpType, fields int, _ error) {
}

// fields are represented as a list
_, fields, err = readListHeader(r)
fields, err = readListHeader(r)

return amqpType(v), fields, err
}

func readListHeader(r *buffer) (size, length int, _ error) {
func readListHeader(r *buffer) (length int, _ error) {
type_, err := r.readType()
if err != nil {
return 0, 0, err
return 0, err
}

listLength := r.len()

switch type_ {
case typeCodeList0:
return 0, 0, nil
return 0, nil
case typeCodeList8:
buf, ok := r.next(2)
if !ok {
return 0, 0, errorNew("invalid length")
return 0, errorNew("invalid length")
}
_ = buf[1]

size = int(buf[0])
if int(size) > listLength-1 {
return 0, 0, errorNew("invalid length")
size := int(buf[0])
if size > listLength-1 {
return 0, errorNew("invalid length")
}
length = int(buf[1])
case typeCodeList32:
buf, ok := r.next(8)
if !ok {
return 0, 0, errorNew("invalid length")
return 0, errorNew("invalid length")
}
_ = buf[7]

size = int(binary.BigEndian.Uint32(buf[:4]))
size := int(binary.BigEndian.Uint32(buf[:4]))
if size > listLength-4 {
return 0, 0, errorNew("invalid length")
return 0, errorNew("invalid length")
}
length = int(binary.BigEndian.Uint32(buf[4:8]))
default:
return 0, 0, errorErrorf("type code %#02x is not a recognized list type", type_)
return 0, errorErrorf("type code %#02x is not a recognized list type", type_)
}

return size, length, nil
return length, nil
}

func readArrayHeader(r *buffer) (size, length int, _ error) {
func readArrayHeader(r *buffer) (length int, _ error) {
type_, err := r.readType()
if err != nil {
return 0, 0, err
return 0, err
}

arrayLength := r.len()
Expand All @@ -485,31 +483,31 @@ func readArrayHeader(r *buffer) (size, length int, _ error) {
case typeCodeArray8:
buf, ok := r.next(2)
if !ok {
return 0, 0, errorNew("invalid length")
return 0, errorNew("invalid length")
}
_ = buf[1]

size = int(buf[0])
if int(size) > arrayLength-1 {
return 0, 0, errorNew("invalid length")
size := int(buf[0])
if size > arrayLength-1 {
return 0, errorNew("invalid length")
}
length = int(buf[1])
case typeCodeArray32:
buf, ok := r.next(8)
if !ok {
return 0, 0, errorNew("invalid length")
return 0, errorNew("invalid length")
}
_ = buf[7]

l := binary.BigEndian.Uint32(buf[:4])
if int(l) > arrayLength-4 {
return 0, 0, errorErrorf("invalid length for type %02x", type_)
size := binary.BigEndian.Uint32(buf[:4])
if int(size) > arrayLength-4 {
return 0, errorErrorf("invalid length for type %02x", type_)
}
length = int(binary.BigEndian.Uint32(buf[4:8]))
default:
return 0, 0, errorErrorf("type code %#02x is not a recognized list type", type_)
return 0, errorErrorf("type code %#02x is not a recognized list type", type_)
}
return size, length, nil
return length, nil
}

func readString(r *buffer) (string, error) {
Expand Down Expand Up @@ -684,7 +682,7 @@ func readAnyMap(r *buffer) (interface{}, error) {

stringKeys := true
Loop:
for key, _ := range m {
for key := range m {
switch key.(type) {
case string:
case symbol:
Expand Down Expand Up @@ -829,7 +827,7 @@ func readComposite(r *buffer) (interface{}, error) {
if len(buf) < 10 {
return nil, errorNew("invalid length for ulong")
}
compositeType = uint64(binary.BigEndian.Uint64(buf[2:]))
compositeType = binary.BigEndian.Uint64(buf[2:])
}

if compositeType > math.MaxUint8 {
Expand Down Expand Up @@ -1196,40 +1194,45 @@ func readUUID(r *buffer) (UUID, error) {
return uuid, nil
}

func readMapHeader(r *buffer) (size uint32, count uint32, _ error) {
func readMapHeader(r *buffer) (count uint32, _ error) {
type_, err := r.readType()
if err != nil {
return 0, 0, err
return 0, err
}

var width int
length := r.len()

switch type_ {
case typeCodeMap8:
buf, ok := r.next(2)
if !ok {
return 0, 0, errorNew("invalid length")
return 0, errorNew("invalid length")
}
_ = buf[1]

size = uint32(buf[0])
size := int(buf[0])
if size > length-1 {
return 0, errorNew("invalid length")
}
count = uint32(buf[1])
width = 1
case typeCodeMap32:
buf, ok := r.next(8)
if !ok {
return 0, 0, errorNew("invalid length")
return 0, errorNew("invalid length")
}
_ = buf[7]

size = binary.BigEndian.Uint32(buf[:4])
size := int(binary.BigEndian.Uint32(buf[:4]))
if size > length-4 {
return 0, errorNew("invalid length")
}
count = binary.BigEndian.Uint32(buf[4:8])
width = 4
default:
return 0, 0, errorErrorf("invalid map type %#02x", type_)
return 0, errorErrorf("invalid map type %#02x", type_)
}

if uint64(size) > uint64(r.len()+width) || uint64(count) > uint64(r.len()) {
return 0, 0, errorNew("invalid length")
if int(count) > r.len() {
return 0, errorNew("invalid length")
}
return size, count, err
return count, nil
}
14 changes: 10 additions & 4 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,11 @@ func writeMap(wr *buffer, m interface{}) error {
case map[string]interface{}:
pairs = len(m) * 2
for key, val := range m {
writeString(wr, key)
err := marshal(wr, val)
err := writeString(wr, key)
if err != nil {
return err
}
err = marshal(wr, val)
if err != nil {
return err
}
Expand All @@ -473,8 +476,11 @@ func writeMap(wr *buffer, m interface{}) error {
case unsettled:
pairs = len(m) * 2
for key, val := range m {
writeString(wr, key)
err := marshal(wr, val)
err := writeString(wr, key)
if err != nil {
return err
}
err = marshal(wr, val)
if err != nil {
return err
}
Expand Down
10 changes: 8 additions & 2 deletions internal/testconn/testconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ func (c *Conn) Close() error {
}

func (c *Conn) LocalAddr() net.Addr {
return &net.TCPAddr{net.IP{127, 0, 0, 1}, 49706, ""}
return &net.TCPAddr{
IP: net.IP{127, 0, 0, 1},
Port: 49706,
}
}

func (c *Conn) RemoteAddr() net.Addr {
return &net.TCPAddr{net.IP{127, 0, 0, 1}, 49706, ""}
return &net.TCPAddr{
IP: net.IP{127, 0, 0, 1},
Port: 49706,
}
}

func (c *Conn) SetDeadline(t time.Time) error {
Expand Down
Loading

0 comments on commit 3ecab7c

Please sign in to comment.