Fixed code smells
This commit is contained in:
@@ -40,16 +40,16 @@ func main() {
|
|||||||
|
|
||||||
c = protocol.Limit(c, func(dir protocol.Direction, p *protocol.Protocol) error {
|
c = protocol.Limit(c, func(dir protocol.Direction, p *protocol.Protocol) error {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return errors.New("No protocol detected")
|
return errors.New("no protocol detected")
|
||||||
}
|
}
|
||||||
if !accept[p.Name] {
|
if !accept[p.Name] {
|
||||||
return fmt.Errorf("Protocol %s is not accepted", p.Name)
|
return fmt.Errorf("protocol %s is not accepted", p.Name)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(os.Stderr, "Accepting protocol %s version %s initiated by %s\n",
|
fmt.Fprintf(os.Stderr, "Accepting protocol %s version %s initiated by %s\n",
|
||||||
p.Name, p.Version, dir)
|
p.Name, p.Version, dir)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
defer c.Close()
|
defer func() { _ = c.Close() }()
|
||||||
|
|
||||||
var wait sync.WaitGroup
|
var wait sync.WaitGroup
|
||||||
wait.Go(func() { multiplex(c, os.Stdin) })
|
wait.Go(func() { multiplex(c, os.Stdin) })
|
||||||
|
@@ -72,8 +72,8 @@ func proxy(client net.Conn, target string) {
|
|||||||
// Create a wait group and copy between client and server bidirectionally,
|
// Create a wait group and copy between client and server bidirectionally,
|
||||||
// either side needs to generate data for the detection to work.
|
// either side needs to generate data for the detection to work.
|
||||||
var group sync.WaitGroup
|
var group sync.WaitGroup
|
||||||
group.Go(func() { io.Copy(client, server) })
|
group.Go(func() { _, _ = io.Copy(client, server) })
|
||||||
group.Go(func() { io.Copy(server, client) })
|
group.Go(func() { _, _ = io.Copy(server, client) })
|
||||||
|
|
||||||
// Wait until the interceptor produces data.
|
// Wait until the interceptor produces data.
|
||||||
result := <-intercepted
|
result := <-intercepted
|
||||||
|
@@ -62,7 +62,7 @@ func detectHTTPRequest(dir Direction, data []byte, srcPort, dstPort int) (proto
|
|||||||
}
|
}
|
||||||
|
|
||||||
var version = Version{Patch: -1}
|
var version = Version{Patch: -1}
|
||||||
fmt.Sscanf(string(part[2]), "HTTP/%d.%d ", &version.Major, &version.Minor)
|
_, _ = fmt.Sscanf(string(part[2]), "HTTP/%d.%d ", &version.Major, &version.Minor)
|
||||||
|
|
||||||
return &Protocol{
|
return &Protocol{
|
||||||
Name: ProtocolHTTP,
|
Name: ProtocolHTTP,
|
||||||
@@ -106,7 +106,7 @@ func detectHTTPResponse(dir Direction, data []byte, srcPort, dstPort int) (proto
|
|||||||
}
|
}
|
||||||
|
|
||||||
var version = Version{Patch: -1}
|
var version = Version{Patch: -1}
|
||||||
fmt.Sscanf(string(data), "HTTP/%d.%d ", &version.Major, &version.Minor)
|
_, _ = fmt.Sscanf(string(data), "HTTP/%d.%d ", &version.Major, &version.Minor)
|
||||||
|
|
||||||
return &Protocol{
|
return &Protocol{
|
||||||
Name: ProtocolHTTP,
|
Name: ProtocolHTTP,
|
||||||
|
@@ -46,7 +46,7 @@ func detectMySQL(dir Direction, data []byte, srcPort, dstPort int) (proto *Proto
|
|||||||
}
|
}
|
||||||
|
|
||||||
var version Version
|
var version Version
|
||||||
fmt.Sscanf(string(data[1:serverVersionEndPos]), "%d.%d.%d-%s", &version.Major, &version.Minor, &version.Patch, &version.Extra)
|
_, _ = fmt.Sscanf(string(data[1:serverVersionEndPos]), "%d.%d.%d-%s", &version.Major, &version.Minor, &version.Patch, &version.Extra)
|
||||||
|
|
||||||
return &Protocol{
|
return &Protocol{
|
||||||
Name: ProtocolMySQL,
|
Name: ProtocolMySQL,
|
||||||
|
@@ -81,7 +81,7 @@ func TestCompareFloats(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "zero equals negative zero",
|
name: "zero equals negative zero",
|
||||||
a: 0.0,
|
a: 0.0,
|
||||||
b: -0.0,
|
b: -0.000000000000000000001,
|
||||||
expected: 0,
|
expected: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user