From 2ee2be089178c83719c81f8eb64e1007407acf7b Mon Sep 17 00:00:00 2001 From: Xing Xing Date: Mon, 23 Dec 2013 17:05:42 +0800 Subject: [PATCH] go fmt --- worker/agent.go | 12 ++++++------ worker/inpack.go | 11 +++++------ worker/worker.go | 14 +++++++------- worker/worker_test.go | 4 ++-- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/worker/agent.go b/worker/agent.go index 7ca3b44..ec159d3 100644 --- a/worker/agent.go +++ b/worker/agent.go @@ -11,17 +11,17 @@ import ( // The agent of job server. type agent struct { - conn net.Conn - worker *Worker - in chan []byte - net, addr string - isConn bool + conn net.Conn + worker *Worker + in chan []byte + net, addr string + isConn bool } // Create the agent of job server. func newAgent(net, addr string, worker *Worker) (a *agent, err error) { a = &agent{ - net: net, + net: net, addr: addr, worker: worker, in: make(chan []byte, QUEUE_SIZE), diff --git a/worker/inpack.go b/worker/inpack.go index 00d954b..25d9da4 100644 --- a/worker/inpack.go +++ b/worker/inpack.go @@ -7,17 +7,17 @@ package worker import ( "bytes" - "fmt" "encoding/binary" + "fmt" "strconv" ) // Worker side job type inPack struct { - dataType uint32 + dataType uint32 data []byte handle, uniqueId, fn string - a *agent + a *agent } // Create a new job @@ -38,7 +38,7 @@ func (inpack *inPack) SendData(data []byte) { l := hl + len(data) + 1 outpack.data = getBuffer(l) copy(outpack.data, []byte(inpack.handle)) - copy(outpack.data[hl + 1:], data) + copy(outpack.data[hl+1:], data) inpack.a.write(outpack) } @@ -49,7 +49,7 @@ func (inpack *inPack) SendWarning(data []byte) { l := hl + len(data) + 1 outpack.data = getBuffer(l) copy(outpack.data, []byte(inpack.handle)) - copy(outpack.data[hl + 1:], data) + copy(outpack.data[hl+1:], data) inpack.a.write(outpack) } @@ -70,7 +70,6 @@ func (inpack *inPack) UpdateStatus(numerator, denominator int) { inpack.a.write(outpack) } - // Decode job from byte slice func decodeInPack(data []byte) (inpack *inPack, l int, err error) { if len(data) < MIN_PACKET_LEN { // valid package should not less 12 bytes diff --git a/worker/worker.go b/worker/worker.go index cd46657..7c75c89 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -5,10 +5,10 @@ package worker import ( - "fmt" - "time" - "sync" "encoding/binary" + "fmt" + "sync" + "time" ) const ( @@ -46,8 +46,8 @@ type Worker struct { Id string // assign a ErrFunc to handle errors ErrorHandler ErrorHandler - JobHandler JobHandler - mutex sync.Mutex + JobHandler JobHandler + mutex sync.Mutex } // Get a new worker @@ -78,7 +78,7 @@ func (worker *Worker) AddServer(net, addr string) (err error) { if err != nil { return err } - worker.agents[net + addr] = a + worker.agents[net+addr] = a return } @@ -120,7 +120,7 @@ func (worker *Worker) addFunc(funcname string, timeout uint32) { outpack.data = getBuffer(l + 5) copy(outpack.data, []byte(funcname)) outpack.data[l] = '\x00' - binary.BigEndian.PutUint32(outpack.data[l + 1:], timeout) + binary.BigEndian.PutUint32(outpack.data[l+1:], timeout) } worker.broadcast(outpack) } diff --git a/worker/worker_test.go b/worker/worker_test.go index 911aa9b..bb0666c 100644 --- a/worker/worker_test.go +++ b/worker/worker_test.go @@ -1,8 +1,8 @@ package worker import ( -"sync" -"testing" + "sync" + "testing" ) var worker *Worker