| Conditions | 7 |
| Total Lines | 67 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | package main |
||
| 37 | if err != nil { |
||
| 38 | t.Fatalf("Failed to dial bufnet: %v", err) |
||
| 39 | } |
||
| 40 | defer conn.Close() |
||
| 41 | client := proto.NewGerduClient(conn) |
||
| 42 | resp, err := client.Put(ctx, &proto.PutRequest{ |
||
| 43 | Key: "Key1", |
||
| 44 | Value: []byte("Value1"), |
||
| 45 | }) |
||
| 46 | if err != nil { |
||
| 47 | t.Fatalf("gRPC Put failed: %v", err) |
||
| 48 | } |
||
| 49 | |||
| 50 | if resp.Created != true { |
||
| 51 | t.Fatalf("gRPC Put could not create the key") |
||
| 52 | } |
||
| 53 | |||
| 54 | response, err := client.Get(ctx, &proto.GetRequest{ |
||
| 55 | Key: "Key1", |
||
| 56 | }) |
||
| 57 | |||
| 58 | if err != nil { |
||
| 59 | t.Fatalf("gRPC Get failed: %v", err) |
||
| 60 | } |
||
| 61 | |||
| 62 | value := string(response.Value) |
||
| 63 | if value != "Value1" { |
||
| 64 | t.Fatalf("gRPC Get the value does not match expecting Value1, but got %v", value) |
||
| 65 | } |
||
| 66 | } |
||
| 67 |