mirror of https://github.com/grpc/grpc-go.git
internal: example flag.Parse() and comments (#2526)
This commit is contained in:
parent
d9bc55b745
commit
463950a151
|
|
@ -284,6 +284,7 @@ func bidirectionalWithMetadata(c pb.EchoClient, message string) {
|
|||
const message = "this is examples/metadata"
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
// Set up a connection to the server.
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -194,6 +194,7 @@ func (s *server) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamin
|
|||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -16,10 +16,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
// Binary client is an example client.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
|
@ -29,9 +31,7 @@ import (
|
|||
hwpb "google.golang.org/grpc/examples/helloworld/helloworld"
|
||||
)
|
||||
|
||||
const (
|
||||
address = "localhost:50051"
|
||||
)
|
||||
var addr = flag.String("addr", "localhost:50051", "the address to connect to")
|
||||
|
||||
// callSayHello calls SayHello on c with the given name, and prints the
|
||||
// response.
|
||||
|
|
@ -56,8 +56,9 @@ func callUnaryEcho(client ecpb.EchoClient, message string) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
// Set up a connection to the server.
|
||||
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
||||
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
// Binary server is an example server.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
|
|
@ -30,9 +33,7 @@ import (
|
|||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
const (
|
||||
port = ":50051"
|
||||
)
|
||||
var port = flag.Int("port", 50051, "the port to serve on")
|
||||
|
||||
// hwServer is used to implement helloworld.GreeterServer.
|
||||
type hwServer struct{}
|
||||
|
|
@ -61,10 +62,13 @@ func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEc
|
|||
}
|
||||
|
||||
func main() {
|
||||
lis, err := net.Listen("tcp", port)
|
||||
flag.Parse()
|
||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
|
||||
if err != nil {
|
||||
log.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
fmt.Printf("server listening at %v\n", lis.Addr())
|
||||
|
||||
s := grpc.NewServer()
|
||||
|
||||
// Register Greeter on the server.
|
||||
|
|
|
|||
Loading…
Reference in New Issue