build: Enable gometalinter "gosimple" check, improve build.go

This commit is contained in:
Jakob Borg
2016-12-18 19:57:41 +01:00
committed by Jakob Borg
parent 47f22ff3e5
commit d41c131364
19 changed files with 108 additions and 130 deletions

View File

@@ -17,10 +17,10 @@ func (p *bufferPool) get(size int) []byte {
return p.new(size)
}
bs := intf.([]byte)
bs := *intf.(*[]byte)
if cap(bs) < size {
// Buffer was too small, leave it for someone else and allocate.
p.put(bs)
p.pool.Put(intf)
return p.new(size)
}
@@ -43,7 +43,7 @@ func (p *bufferPool) upgrade(bs []byte, size int) []byte {
// put returns the buffer to the pool
func (p *bufferPool) put(bs []byte) {
p.pool.Put(bs)
p.pool.Put(&bs)
}
// new creates a new buffer of the requested size, taking the minimum

View File

@@ -105,11 +105,7 @@ func readHello(c io.Reader) (HelloResult, error) {
if err := hello.UnmarshalXDR(buf); err != nil {
return HelloResult{}, err
}
res := HelloResult{
DeviceName: hello.DeviceName,
ClientName: hello.ClientName,
ClientVersion: hello.ClientVersion,
}
res := HelloResult(hello)
return res, ErrTooOldVersion13
case 0x00010001, 0x00010000:

View File

@@ -516,7 +516,7 @@ func (c *rawConnection) handleRequest(req Request) {
var done chan struct{}
if usePool {
buf = c.pool.Get().([]byte)[:size]
buf = (*c.pool.Get().(*[]byte))[:size]
done = make(chan struct{})
} else {
buf = make([]byte, size)
@@ -539,7 +539,7 @@ func (c *rawConnection) handleRequest(req Request) {
if usePool {
<-done
c.pool.Put(buf)
c.pool.Put(&buf)
}
}
@@ -762,11 +762,12 @@ func (c *rawConnection) close(err error) {
// results in an effecting ping interval of somewhere between
// PingSendInterval/2 and PingSendInterval.
func (c *rawConnection) pingSender() {
ticker := time.Tick(PingSendInterval / 2)
ticker := time.NewTicker(PingSendInterval / 2)
defer ticker.Stop()
for {
select {
case <-ticker:
case <-ticker.C:
d := time.Since(c.cw.Last())
if d < PingSendInterval/2 {
l.Debugln(c.id, "ping skipped after wr", d)
@@ -786,11 +787,12 @@ func (c *rawConnection) pingSender() {
// but we expect pings in the absence of other messages) within the last
// ReceiveTimeout. If not, we close the connection with an ErrTimeout.
func (c *rawConnection) pingReceiver() {
ticker := time.Tick(ReceiveTimeout / 2)
ticker := time.NewTicker(ReceiveTimeout / 2)
defer ticker.Stop()
for {
select {
case <-ticker:
case <-ticker.C:
d := time.Since(c.cr.Last())
if d > ReceiveTimeout {
l.Debugln(c.id, "ping timeout", d)