Skip to content

Commit 476453c

Browse files
Server Grpc after test. Missing data base connection implementation
1 parent e8d8aff commit 476453c

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

logClient/main.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ func main() {
2828
name := defaultName
2929
if len(os.Args) > 1 {
3030
name = os.Args[1]
31-
delay = os.Args[2]
3231
}
3332
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
3433
defer cancel()
35-
r, err := c.LogTestData(ctx, &pb.Log{blockID: name, request_delay: delay, blockDelivered: true})
34+
_, err = c.SendLogs(ctx, &pb.Log{BlockID: name, RequestDelay: 100, BlockDelay:200, BlockDelivered: true})
3635
if err != nil {
3736
log.Fatalf("could not greet: %v", err)
3837
}
39-
log.Printf("Greeting: %s", r.GetMessage())
38+
4039
}

logServer/main.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88

99
"google.golang.org/grpc"
1010
pb "github.com/Matias-Correia/go-test_server/protologs"
11-
durationpb "google.golang.org/protobuf/types/known/durationpb"
12-
emptypb "google.golang.org/protobuf/types/known/emptypb"
1311
)
1412

1513
const (
@@ -22,18 +20,19 @@ type server struct {
2220
}
2321

2422
// LogTestData implements protologs.LogTestData
25-
func (s *server) LogTestData(ctx context.Context, in *pb.Log) (*pb.google.protobuf.Empty, error) {
23+
func (s *server) SendLogs(ctx context.Context, in *pb.Log) (*pb.Empty, error) {
2624
log.Printf("Received: %v", in.GetBlockID())
2725
log.Printf("Was delivered?: %v", in.GetBlockDelivered())
28-
log.Printf("With Delay: %v", in.GetRequestDelay())
29-
30-
RecordReceivedLogs(in.GetBlockID, in.GetRequestDelay, in.GetBlockDelivered)
26+
log.Printf("Request Delay: %v", in.GetRequestDelay())
27+
log.Printf("Block Delay: %v", in.GetBlockDelay())
28+
29+
RecordReceivedLogs(in.GetBlockID(), time.Duration(in.GetRequestDelay()) * time.Millisecond, in.GetBlockDelivered())
3130

32-
return *emptypb.Empty, nil
31+
return &(pb.Empty{}), nil
3332
}
3433

3534
// Save info in the BD
36-
func RecordReceivedLogs(blockId string, delay time.Duration, bool blockDelivered){
35+
func RecordReceivedLogs(blockId string, delay time.Duration, blockDelivered bool){
3736

3837
}
3938

protologs/logs.pb.go

+27-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protologs/logs.proto

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ service LogTestData{
1414
message Empty{}
1515

1616
// Log definition
17-
//Tempo desde que peço o request até que começo a receber o bloco
1817
message Log{
1918
string blockID = 1;
2019
int64 request_delay = 2;
21-
bool blockDelivered = 3;
20+
int64 block_delay = 3;
21+
bool blockDelivered = 4;
2222
}

0 commit comments

Comments
 (0)