Skip to content

Commit

Permalink
Suppress warnings (googleforgames#16)
Browse files Browse the repository at this point in the history
* make it testable

* replace deprecated one

* remove some warnings

* make it like Golang style more

* adopt shorter name for some variables
  • Loading branch information
shin5ok authored Mar 9, 2023
1 parent e333e5e commit 082fb8f
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func matchmake(ws *websocket.Conn) {
stream := protostream.NewProtoStream(ws)

ctx, cancel := context.WithCancel(ws.Request().Context())
defer cancel()
assignments := make(chan *pb.Assignment)
errs := make(chan error)

Expand Down Expand Up @@ -79,24 +80,22 @@ func matchmake(ws *websocket.Conn) {
func streamAssignments(ctx context.Context, assignments chan *pb.Assignment, errs chan error) {
conn, err := grpc.Dial("open-match-frontend.open-match.svc.cluster.local:50504", grpc.WithInsecure())
if err != nil {
errs <- fmt.Errorf("Error dialing open match: %w", err)
errs <- fmt.Errorf("error dialing open match: %w", err)
}
defer conn.Close()
fe := pb.NewFrontendServiceClient(conn)

var ticketId string
{
req := &pb.CreateTicketRequest{
Ticket: &pb.Ticket{},
}
crReq := &pb.CreateTicketRequest{
Ticket: &pb.Ticket{},
}

resp, err := fe.CreateTicket(ctx, req)
if err != nil {
errs <- fmt.Errorf("Error creating open match ticket: %w", err)
return
}
ticketId = resp.Id
resp, err := fe.CreateTicket(ctx, crReq)
if err != nil {
errs <- fmt.Errorf("error creating open match ticket: %w", err)
return
}
ticketId = resp.Id

defer func() {
_, err := fe.DeleteTicket(context.Background(), &pb.DeleteTicketRequest{TicketId: ticketId})
Expand All @@ -105,23 +104,21 @@ func streamAssignments(ctx context.Context, assignments chan *pb.Assignment, err
}
}()

{
req := &pb.WatchAssignmentsRequest{
TicketId: ticketId,
}
waReq := &pb.WatchAssignmentsRequest{
TicketId: ticketId,
}

stream, err := fe.WatchAssignments(ctx, req)
stream, err := fe.WatchAssignments(ctx, waReq)
if err != nil {
errs <- fmt.Errorf("error getting assignment stream: %w", err)
return
}
for {
resp, err := stream.Recv()
if err != nil {
errs <- fmt.Errorf("Error getting assignment stream: %w", err)
errs <- fmt.Errorf("error streaming assignment: %w", err)
return
}
for {
resp, err := stream.Recv()
if err != nil {
errs <- fmt.Errorf("Error streaming assignment: %w", err)
return
}
assignments <- resp.Assignment
}
assignments <- resp.Assignment
}
}

0 comments on commit 082fb8f

Please # to comment.