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

This commit is contained in:
Tzu-Jung Lee
2017-01-17 00:26:32 -08:00
parent af2a66b226
commit 55cb08722d
8 changed files with 32 additions and 42 deletions

View File

@ -50,11 +50,10 @@ RETRY_LOOP:
if err != nil { if err != nil {
if cli.mustConnect { if cli.mustConnect {
return err 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) client := types.NewABCIApplicationClient(conn)
@ -268,11 +267,10 @@ func (cli *grpcClient) InfoSync() (resInfo types.ResponseInfo, err error) {
if err = cli.Error(); err != nil { if err = cli.Error(); err != nil {
return resInfo, err return resInfo, err
} }
if resInfo_ := reqres.Response.GetInfo(); resInfo_ != nil { if info := reqres.Response.GetInfo(); info != nil {
return *resInfo_, nil return *info, nil
} else {
return resInfo, nil
} }
return resInfo, nil
} }
func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result) { 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 { if err := cli.Error(); err != nil {
return resEndBlock, err return resEndBlock, err
} }
if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil { if blk := reqres.Response.GetEndBlock(); blk != nil {
return *resEndBlock_, nil return *blk, nil
} else {
return resEndBlock, nil
} }
return resEndBlock, nil
} }

View File

@ -69,11 +69,10 @@ RETRY_LOOP:
if err != nil { if err != nil {
if cli.mustConnect { if cli.mustConnect {
return err 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 cli.conn = conn
@ -82,7 +81,6 @@ RETRY_LOOP:
return nil return nil
} }
return nil // never happens
} }
func (cli *socketClient) OnStop() { func (cli *socketClient) OnStop() {
@ -298,11 +296,10 @@ func (cli *socketClient) InfoSync() (resInfo types.ResponseInfo, err error) {
if err := cli.Error(); err != nil { if err := cli.Error(); err != nil {
return resInfo, err return resInfo, err
} }
if resInfo_ := reqres.Response.GetInfo(); resInfo_ != nil { if info := reqres.Response.GetInfo(); info != nil {
return *resInfo_, nil return *info, nil
} else {
return resInfo, nil
} }
return resInfo, nil
} }
func (cli *socketClient) SetOptionSync(key string, value string) (res types.Result) { 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 { if err := cli.Error(); err != nil {
return resEndBlock, err return resEndBlock, err
} }
if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil { if blk := reqres.Response.GetEndBlock(); blk != nil {
return *resEndBlock_, nil return *blk, nil
} else {
return resEndBlock, nil
} }
return resEndBlock, nil
} }
//---------------------------------------- //----------------------------------------

View File

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

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)) return types.ErrBadNonce.SetLog(fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue))
} }
} }
app.txCount += 1 app.txCount++
return types.OK return types.OK
} }
@ -60,15 +60,13 @@ func (app *CounterApplication) CheckTx(tx []byte) types.Result {
} }
func (app *CounterApplication) Commit() types.Result { func (app *CounterApplication) Commit() types.Result {
app.hashCount += 1 app.hashCount++
if app.txCount == 0 { if app.txCount == 0 {
return types.OK 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 { func (app *CounterApplication) Query(query []byte) types.Result {

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@ package main
import ( import (
"bufio" "bufio"
"errors"
"fmt" "fmt"
"log" "log"
"net" "net"
@ -27,7 +26,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err.Error()) log.Fatal(err.Error())
} }
counter += 1 counter++
if counter%1000 == 0 { if counter%1000 == 0 {
fmt.Println(counter) fmt.Println(counter)
} }
@ -63,7 +62,7 @@ func makeRequest(conn net.Conn, req *types.Request) (*types.Response, error) {
return nil, err return nil, err
} }
if _, ok := resFlush.Value.(*types.Response_Flush); !ok { 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 return res, nil