Skip to content

Instantly share code, notes, and snippets.

@dipeshdulal
Created July 12, 2020 03:43
Show Gist options
  • Save dipeshdulal/23e590523d3b08438b4c0bf5a054aca4 to your computer and use it in GitHub Desktop.
Save dipeshdulal/23e590523d3b08438b4c0bf5a054aca4 to your computer and use it in GitHub Desktop.
Join Channel Client Side
func joinChannel(ctx context.Context, client chatpb.ChatServiceClient) {
channel := chatpb.Channel{Name: *channelName, SendersName: *senderName}
stream, err := client.JoinChannel(ctx, &channel)
if err != nil {
log.Fatalf("client.JoinChannel(ctx, &channel) throws: %v", err)
}
fmt.Printf("Joined channel: %v \n", *channelName)
waitc := make(chan struct{})
go func() {
for {
in, err := stream.Recv()
if err == io.EOF {
close(waitc)
return
}
if err != nil {
log.Fatalf("Failed to receive message from channel joining. \nErr: %v", err)
}
if *senderName != in.Sender {
fmt.Printf("MESSAGE: (%v) -> %v \n", in.Sender, in.Message)
}
}
}()
<-waitc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment