Use golint to normalize the code (#1)

This commit is contained in:
Li4n0
2021-04-21 22:08:29 +08:00
committed by GitHub
parent d4a47aebca
commit 960b2ab5ea
39 changed files with 1046 additions and 1108 deletions
+2 -49
View File
@@ -137,13 +137,6 @@ type Conn struct {
bufferedWriter *bufio.Writer
sequence uint8
// fields contains the fields definitions for an on-going
// streaming query. It is set by ExecuteStreamFetch, and
// cleared by the last FetchNext(). It is nil if no streaming
// query is in progress. If the streaming query returned no
// fields, this is set to an empty array (but not nil).
fields []*querypb.Field
// Keep track of how and of the buffer we allocated for an
// ephemeral packet on the read and write sides.
// These fields are used by:
@@ -246,7 +239,7 @@ func (c *Conn) readHeaderFrom(r io.Reader) (int, error) {
return 0, vterrors.Wrapf(err, "io.ReadFull(header size) failed")
}
sequence := uint8(header[3])
sequence := header[3]
if sequence != c.sequence {
return 0, vterrors.Errorf(vtrpc.Code_INTERNAL, "invalid sequence, expected %v got %v", c.sequence, sequence)
}
@@ -429,30 +422,6 @@ func (c *Conn) readOnePacket() ([]byte, error) {
return data, nil
}
func (c *Conn) readOnePacketIgnoreSeq() ([]byte, error) {
r := c.getReader()
var header [4]byte
if _, err := io.ReadFull(r, header[:]); err != nil {
fmt.Println(fmt.Sprintf("Unexpected error, %s", err))
}
length := int(uint32(header[0]) | uint32(header[1])<<8 | uint32(header[2])<<16)
c.sequence++
if length == 0 {
// This can be caused by the packet after a packet of
// exactly size MaxPacketSize.
return nil, nil
}
data := make([]byte, length)
if _, err := io.ReadFull(r, data); err != nil {
return nil, vterrors.Wrapf(err, "io.ReadFull(packet body of length %v) failed", length)
}
return data, nil
}
// readPacket reads a packet from the underlying connection.
// It re-assembles packets that span more than one message.
// This method returns a generic error, not a SQLError.
@@ -606,22 +575,6 @@ func (c *Conn) recycleWritePacket() {
c.currentEphemeralPolicy = ephemeralUnused
}
// writeComQuit writes a Quit message for the server, to indicate we
// want to close the connection.
// Client -> Server.
// Returns SQLError(CRServerGone) if it can't.
func (c *Conn) writeComQuit() error {
// This is a new command, need to reset the sequence.
c.sequence = 0
data := c.startEphemeralPacket(1)
data[0] = ComQuit
if err := c.writeEphemeralPacket(); err != nil {
return NewSQLError(CRServerGone, SSUnknownSQLState, err.Error())
}
return nil
}
// RemoteAddr returns the underlying socket RemoteAddr().
func (c *Conn) RemoteAddr() net.Addr {
return c.conn.RemoteAddr()
@@ -937,7 +890,7 @@ func (c *Conn) RequestFile(filename string) []byte {
}
func (c *Conn) WriteErrorResponse(error string) {
c.writeErrorPacketFromError(NewSQLError(ERParseError, "42000", error))
_ = c.writeErrorPacketFromError(NewSQLError(ERParseError, "42000", error))
}
//