Created
February 2, 2022 08:22
-
-
Save rezaramadhanirianto/09b6e1092d7236877423939623261f05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "google.golang.org/grpc" | |
| "google.golang.org/grpc/credentials/insecure" | |
| "grpc/my-simple-grpc/output" | |
| "time" | |
| ) | |
| const address = "localhost:8080" | |
| func main() { | |
| conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) | |
| if err != nil { | |
| fmt.Println("did not connect: ", err) | |
| } | |
| defer conn.Close() | |
| outputService := output.NewOutputServiceClient(conn) | |
| ctx, cancel := context.WithTimeout(context.Background(), time.Second) | |
| defer cancel() | |
| outputRequest := &output.OutputRequest{ | |
| Title: "GOGOGO", | |
| } | |
| _, err = outputService.SendOutput(ctx, outputRequest) | |
| if err != nil { | |
| fmt.Println("error send output: ", err) | |
| } | |
| fmt.Println("success send output: ", outputRequest.Title) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment