Use log instead of grpclog in routeguide example (#1395)
This commit is contained in:
Родитель
971efedc20
Коммит
98bc2cec5b
|
@ -25,6 +25,7 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
|
@ -32,7 +33,6 @@ import (
|
|||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
pb "google.golang.org/grpc/examples/route_guide/routeguide"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/testdata"
|
||||
)
|
||||
|
||||
|
@ -45,20 +45,20 @@ var (
|
|||
|
||||
// printFeature gets the feature for the given point.
|
||||
func printFeature(client pb.RouteGuideClient, point *pb.Point) {
|
||||
grpclog.Printf("Getting feature for point (%d, %d)", point.Latitude, point.Longitude)
|
||||
log.Printf("Getting feature for point (%d, %d)", point.Latitude, point.Longitude)
|
||||
feature, err := client.GetFeature(context.Background(), point)
|
||||
if err != nil {
|
||||
grpclog.Fatalf("%v.GetFeatures(_) = _, %v: ", client, err)
|
||||
log.Fatalf("%v.GetFeatures(_) = _, %v: ", client, err)
|
||||
}
|
||||
grpclog.Println(feature)
|
||||
log.Println(feature)
|
||||
}
|
||||
|
||||
// printFeatures lists all the features within the given bounding Rectangle.
|
||||
func printFeatures(client pb.RouteGuideClient, rect *pb.Rectangle) {
|
||||
grpclog.Printf("Looking for features within %v", rect)
|
||||
log.Printf("Looking for features within %v", rect)
|
||||
stream, err := client.ListFeatures(context.Background(), rect)
|
||||
if err != nil {
|
||||
grpclog.Fatalf("%v.ListFeatures(_) = _, %v", client, err)
|
||||
log.Fatalf("%v.ListFeatures(_) = _, %v", client, err)
|
||||
}
|
||||
for {
|
||||
feature, err := stream.Recv()
|
||||
|
@ -66,9 +66,9 @@ func printFeatures(client pb.RouteGuideClient, rect *pb.Rectangle) {
|
|||
break
|
||||
}
|
||||
if err != nil {
|
||||
grpclog.Fatalf("%v.ListFeatures(_) = _, %v", client, err)
|
||||
log.Fatalf("%v.ListFeatures(_) = _, %v", client, err)
|
||||
}
|
||||
grpclog.Println(feature)
|
||||
log.Println(feature)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,21 +81,21 @@ func runRecordRoute(client pb.RouteGuideClient) {
|
|||
for i := 0; i < pointCount; i++ {
|
||||
points = append(points, randomPoint(r))
|
||||
}
|
||||
grpclog.Printf("Traversing %d points.", len(points))
|
||||
log.Printf("Traversing %d points.", len(points))
|
||||
stream, err := client.RecordRoute(context.Background())
|
||||
if err != nil {
|
||||
grpclog.Fatalf("%v.RecordRoute(_) = _, %v", client, err)
|
||||
log.Fatalf("%v.RecordRoute(_) = _, %v", client, err)
|
||||
}
|
||||
for _, point := range points {
|
||||
if err := stream.Send(point); err != nil {
|
||||
grpclog.Fatalf("%v.Send(%v) = %v", stream, point, err)
|
||||
log.Fatalf("%v.Send(%v) = %v", stream, point, err)
|
||||
}
|
||||
}
|
||||
reply, err := stream.CloseAndRecv()
|
||||
if err != nil {
|
||||
grpclog.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil)
|
||||
log.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil)
|
||||
}
|
||||
grpclog.Printf("Route summary: %v", reply)
|
||||
log.Printf("Route summary: %v", reply)
|
||||
}
|
||||
|
||||
// runRouteChat receives a sequence of route notes, while sending notes for various locations.
|
||||
|
@ -110,7 +110,7 @@ func runRouteChat(client pb.RouteGuideClient) {
|
|||
}
|
||||
stream, err := client.RouteChat(context.Background())
|
||||
if err != nil {
|
||||
grpclog.Fatalf("%v.RouteChat(_) = _, %v", client, err)
|
||||
log.Fatalf("%v.RouteChat(_) = _, %v", client, err)
|
||||
}
|
||||
waitc := make(chan struct{})
|
||||
go func() {
|
||||
|
@ -122,14 +122,14 @@ func runRouteChat(client pb.RouteGuideClient) {
|
|||
return
|
||||
}
|
||||
if err != nil {
|
||||
grpclog.Fatalf("Failed to receive a note : %v", err)
|
||||
log.Fatalf("Failed to receive a note : %v", err)
|
||||
}
|
||||
grpclog.Printf("Got message %s at point(%d, %d)", in.Message, in.Location.Latitude, in.Location.Longitude)
|
||||
log.Printf("Got message %s at point(%d, %d)", in.Message, in.Location.Latitude, in.Location.Longitude)
|
||||
}
|
||||
}()
|
||||
for _, note := range notes {
|
||||
if err := stream.Send(note); err != nil {
|
||||
grpclog.Fatalf("Failed to send a note: %v", err)
|
||||
log.Fatalf("Failed to send a note: %v", err)
|
||||
}
|
||||
}
|
||||
stream.CloseSend()
|
||||
|
@ -151,7 +151,7 @@ func main() {
|
|||
}
|
||||
creds, err := credentials.NewClientTLSFromFile(*caFile, *serverHostOverride)
|
||||
if err != nil {
|
||||
grpclog.Fatalf("Failed to create TLS credentials %v", err)
|
||||
log.Fatalf("Failed to create TLS credentials %v", err)
|
||||
}
|
||||
opts = append(opts, grpc.WithTransportCredentials(creds))
|
||||
} else {
|
||||
|
@ -159,7 +159,7 @@ func main() {
|
|||
}
|
||||
conn, err := grpc.Dial(*serverAddr, opts...)
|
||||
if err != nil {
|
||||
grpclog.Fatalf("fail to dial: %v", err)
|
||||
log.Fatalf("fail to dial: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
client := pb.NewRouteGuideClient(conn)
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"net"
|
||||
"time"
|
||||
|
@ -36,7 +37,6 @@ import (
|
|||
"google.golang.org/grpc"
|
||||
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/testdata"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
@ -145,10 +145,10 @@ func (s *routeGuideServer) RouteChat(stream pb.RouteGuide_RouteChatServer) error
|
|||
func (s *routeGuideServer) loadFeatures(filePath string) {
|
||||
file, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
grpclog.Fatalf("Failed to load default features: %v", err)
|
||||
log.Fatalf("Failed to load default features: %v", err)
|
||||
}
|
||||
if err := json.Unmarshal(file, &s.savedFeatures); err != nil {
|
||||
grpclog.Fatalf("Failed to load default features: %v", err)
|
||||
log.Fatalf("Failed to load default features: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ func main() {
|
|||
flag.Parse()
|
||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
|
||||
if err != nil {
|
||||
grpclog.Fatalf("failed to listen: %v", err)
|
||||
log.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
var opts []grpc.ServerOption
|
||||
if *tls {
|
||||
|
@ -221,7 +221,7 @@ func main() {
|
|||
}
|
||||
creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
|
||||
if err != nil {
|
||||
grpclog.Fatalf("Failed to generate credentials %v", err)
|
||||
log.Fatalf("Failed to generate credentials %v", err)
|
||||
}
|
||||
opts = []grpc.ServerOption{grpc.Creds(creds)}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче