Browse Source

lint: s/+=1/++, remove else clauses

pull/1780/head
Tzu-Jung Lee 8 years ago
parent
commit
55cb08722d
8 changed files with 32 additions and 42 deletions
  1. +9
    -12
      client/grpc_client.go
  2. +9
    -13
      client/socket_client.go
  3. +2
    -2
      example/chain_aware/chain_aware_app.go
  4. +5
    -7
      example/counter/counter.go
  5. +2
    -2
      example/example_test.go
  6. +1
    -1
      server/socket_server.go
  7. +2
    -2
      tests/benchmarks/parallel/parallel.go
  8. +2
    -3
      tests/benchmarks/simple/simple.go

+ 9
- 12
client/grpc_client.go View File

@ -50,11 +50,10 @@ RETRY_LOOP:
if err != nil {
if cli.mustConnect {
return err
} else {
log.Warn(fmt.Sprintf("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
log.Warn(fmt.Sprintf("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
client := types.NewABCIApplicationClient(conn)
@ -268,11 +267,10 @@ func (cli *grpcClient) InfoSync() (resInfo types.ResponseInfo, err error) {
if err = cli.Error(); err != nil {
return resInfo, err
}
if resInfo_ := reqres.Response.GetInfo(); resInfo_ != nil {
return *resInfo_, nil
} else {
return resInfo, nil
if info := reqres.Response.GetInfo(); info != nil {
return *info, nil
}
return resInfo, nil
}
func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result) {
@ -335,9 +333,8 @@ func (cli *grpcClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEn
if err := cli.Error(); err != nil {
return resEndBlock, err
}
if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil {
return *resEndBlock_, nil
} else {
return resEndBlock, nil
if blk := reqres.Response.GetEndBlock(); blk != nil {
return *blk, nil
}
return resEndBlock, nil
}

+ 9
- 13
client/socket_client.go View File

@ -69,11 +69,10 @@ RETRY_LOOP:
if err != nil {
if cli.mustConnect {
return err
} else {
log.Warn(fmt.Sprintf("abci.socketClient failed to connect to %v. Retrying...", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
log.Warn(fmt.Sprintf("abci.socketClient failed to connect to %v. Retrying...", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
cli.conn = conn
@ -82,7 +81,6 @@ RETRY_LOOP:
return nil
}
return nil // never happens
}
func (cli *socketClient) OnStop() {
@ -298,11 +296,10 @@ func (cli *socketClient) InfoSync() (resInfo types.ResponseInfo, err error) {
if err := cli.Error(); err != nil {
return resInfo, err
}
if resInfo_ := reqres.Response.GetInfo(); resInfo_ != nil {
return *resInfo_, nil
} else {
return resInfo, nil
if info := reqres.Response.GetInfo(); info != nil {
return *info, nil
}
return resInfo, nil
}
func (cli *socketClient) SetOptionSync(key string, value string) (res types.Result) {
@ -379,11 +376,10 @@ func (cli *socketClient) EndBlockSync(height uint64) (resEndBlock types.Response
if err := cli.Error(); err != nil {
return resEndBlock, err
}
if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil {
return *resEndBlock_, nil
} else {
return resEndBlock, nil
if blk := reqres.Response.GetEndBlock(); blk != nil {
return *blk, nil
}
return resEndBlock, nil
}
//----------------------------------------


+ 2
- 2
example/chain_aware/chain_aware_app.go View File

@ -64,12 +64,12 @@ func (app *ChainAwareApplication) Query(query []byte) types.Result {
}
func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
app.beginCount += 1
app.beginCount++
return
}
func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
app.endCount += 1
app.endCount++
return
}


+ 5
- 7
example/counter/counter.go View File

@ -40,7 +40,7 @@ func (app *CounterApplication) DeliverTx(tx []byte) types.Result {
return types.ErrBadNonce.SetLog(fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue))
}
}
app.txCount += 1
app.txCount++
return types.OK
}
@ -60,15 +60,13 @@ func (app *CounterApplication) CheckTx(tx []byte) types.Result {
}
func (app *CounterApplication) Commit() types.Result {
app.hashCount += 1
app.hashCount++
if app.txCount == 0 {
return types.OK
} else {
hash := make([]byte, 8)
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
return types.NewResultOK(hash, "")
}
hash := make([]byte, 8)
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
return types.NewResultOK(hash, "")
}
func (app *CounterApplication) Query(query []byte) types.Result {


+ 2
- 2
example/example_test.go View File

@ -60,7 +60,7 @@ func testStream(t *testing.T, app types.Application) {
// Process response
switch r := res.Value.(type) {
case *types.Response_DeliverTx:
counter += 1
counter++
if r.DeliverTx.Code != types.CodeType_OK {
t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
}
@ -135,7 +135,7 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
if err != nil {
t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
}
counter += 1
counter++
if response.Code != types.CodeType_OK {
t.Error("DeliverTx failed with ret_code", response.Code)
}


+ 1
- 1
server/socket_server.go View File

@ -72,7 +72,7 @@ func (s *SocketServer) addConn(conn net.Conn) int {
defer s.connsMtx.Unlock()
connID := s.nextConnID
s.nextConnID += 1
s.nextConnID++
s.conns[connID] = conn
return connID


+ 2
- 2
tests/benchmarks/parallel/parallel.go View File

@ -25,7 +25,7 @@ func main() {
if err != nil {
log.Fatal(err.Error())
}
counter += 1
counter++
if counter%1000 == 0 {
fmt.Println("Read", counter)
}
@ -47,7 +47,7 @@ func main() {
log.Fatal(err.Error())
}
counter += 1
counter++
if counter%1000 == 0 {
fmt.Println("Write", counter)
}


+ 2
- 3
tests/benchmarks/simple/simple.go View File

@ -2,7 +2,6 @@ package main
import (
"bufio"
"errors"
"fmt"
"log"
"net"
@ -27,7 +26,7 @@ func main() {
if err != nil {
log.Fatal(err.Error())
}
counter += 1
counter++
if counter%1000 == 0 {
fmt.Println(counter)
}
@ -63,7 +62,7 @@ func makeRequest(conn net.Conn, req *types.Request) (*types.Response, error) {
return nil, err
}
if _, ok := resFlush.Value.(*types.Response_Flush); !ok {
return nil, errors.New(fmt.Sprintf("Expected flush response but got something else: %v", reflect.TypeOf(resFlush)))
return nil, fmt.Errorf("Expected flush response but got something else: %v", reflect.TypeOf(resFlush))
}
return res, nil


Loading…
Cancel
Save