Fix lint errors

This commit is contained in:
9seconds
2018-07-09 16:11:05 +03:00
parent fb00cd1121
commit 29b5130c95
32 changed files with 207 additions and 55 deletions
+18 -7
View File
@@ -9,6 +9,9 @@ import (
"github.com/9seconds/mtg/stats"
)
// ConnPurpose is intented to be identifier of connection purpose. We
// sometimes want to treat client/telegram connection differently (for
// logging for example).
type ConnPurpose uint8
func (c ConnPurpose) String() string {
@@ -22,6 +25,7 @@ func (c ConnPurpose) String() string {
return ""
}
// ConnPurpose* define different connection types.
const (
ConnPurposeClient = iota
ConnPurposeTelegram
@@ -32,6 +36,8 @@ const (
connTimeoutWrite = 5 * time.Minute
)
// Conn is a basic wrapper for net.Conn providing the most low-level
// logic and management as possible.
type Conn struct {
connID string
conn net.Conn
@@ -42,7 +48,7 @@ type Conn struct {
}
func (c *Conn) Write(p []byte) (int, error) {
c.conn.SetWriteDeadline(time.Now().Add(connTimeoutWrite))
c.conn.SetWriteDeadline(time.Now().Add(connTimeoutWrite)) // nolint: errcheck
n, err := c.conn.Write(p)
c.logger.Debugw("Write to stream", "bytes", n, "error", err)
@@ -52,7 +58,7 @@ func (c *Conn) Write(p []byte) (int, error) {
}
func (c *Conn) Read(p []byte) (int, error) {
c.conn.SetReadDeadline(time.Now().Add(connTimeoutRead))
c.conn.SetReadDeadline(time.Now().Add(connTimeoutRead)) // nolint: errcheck
n, err := c.conn.Read(p)
c.logger.Debugw("Read from stream", "bytes", n, "error", err)
@@ -61,11 +67,18 @@ func (c *Conn) Read(p []byte) (int, error) {
return n, err
}
// Close closes underlying net.Conn instance.
func (c *Conn) Close() error {
defer c.logger.Debugw("Closed connection")
defer c.logger.Debugw("Close connection")
return c.conn.Close()
}
// Logger returns an instance of the logger for this wrapper.
func (c *Conn) Logger() *zap.SugaredLogger {
return c.logger
}
// LocalAddr returns local address of the underlying net.Conn.
func (c *Conn) LocalAddr() *net.TCPAddr {
addr := c.conn.LocalAddr().(*net.TCPAddr)
newAddr := *addr
@@ -81,14 +94,12 @@ func (c *Conn) LocalAddr() *net.TCPAddr {
return &newAddr
}
// RemoteAddr returns remote address of the underlying net.Conn.
func (c *Conn) RemoteAddr() *net.TCPAddr {
return c.conn.RemoteAddr().(*net.TCPAddr)
}
func (c *Conn) Logger() *zap.SugaredLogger {
return c.logger
}
// NewConn initializes Conn wrapper for net.Conn.
func NewConn(conn net.Conn, connID string, purpose ConnPurpose, publicIPv4, publicIPv6 net.IP) StreamReadWriteCloser {
logger := zap.S().With(
"connection_id", connID,