Cosmetic updates to the route guide example
This commit is contained in:
Родитель
385ff1a296
Коммит
46f39d3ebd
|
@ -51,10 +51,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
tls = flag.Bool("use_tls", false, "Connection uses TLS if true, else plain TCP")
|
||||
caFile = flag.String("tls_ca_file", "testdata/ca.pem", "The file containning the CA root cert file")
|
||||
serverAddr = flag.String("server_addr", "127.0.0.1:10000", "The server address in the format of host:port")
|
||||
tlsServerName = flag.String("server_host_override", "x.test.youtube.com", "The server name use to verify the hostname returned by TLS handshake")
|
||||
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
|
||||
caFile = flag.String("ca_file", "testdata/ca.pem", "The file containning the CA root cert file")
|
||||
serverAddr = flag.String("server_addr", "127.0.0.1:10000", "The server address in the format of host:port")
|
||||
serverHostOverride = flag.String("server_host_override", "x.test.youtube.com", "The server name use to verify the hostname returned by TLS handshake")
|
||||
)
|
||||
|
||||
// printFeature gets the feature for the given point.
|
||||
|
@ -63,9 +63,9 @@ func printFeature(client pb.RouteGuideClient, point *pb.Point) {
|
|||
feature, err := client.GetFeature(context.Background(), point)
|
||||
if err != nil {
|
||||
log.Fatalf("%v.GetFeatures(_) = _, %v: ", client, err)
|
||||
return
|
||||
} else {
|
||||
log.Println(feature)
|
||||
}
|
||||
log.Println(feature)
|
||||
}
|
||||
|
||||
// printFeatures lists all the features within the given bounding Rectangle.
|
||||
|
@ -162,8 +162,8 @@ func main() {
|
|||
var opts []grpc.DialOption
|
||||
if *tls {
|
||||
var sn string
|
||||
if *tlsServerName != "" {
|
||||
sn = *tlsServerName
|
||||
if *serverHostOverride != "" {
|
||||
sn = *serverHostOverride
|
||||
}
|
||||
var creds credentials.TransportAuthenticator
|
||||
if *caFile != "" {
|
||||
|
|
|
@ -59,10 +59,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
tls = flag.Bool("use_tls", false, "Connection uses TLS if true, else plain TCP")
|
||||
certFile = flag.String("tls_cert_file", "testdata/server1.pem", "The TLS cert file")
|
||||
keyFile = flag.String("tls_key_file", "testdata/server1.key", "The TLS key file")
|
||||
jsonDBFile = flag.String("route_guide_db", "testdata/route_guide_db.json", "A json file containing a list of features")
|
||||
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
|
||||
certFile = flag.String("cert_file", "testdata/server1.pem", "The TLS cert file")
|
||||
keyFile = flag.String("key_file", "testdata/server1.key", "The TLS key file")
|
||||
jsonDBFile = flag.String("json_db_file", "testdata/route_guide_db.json", "A json file containing a list of features")
|
||||
port = flag.Int("port", 10000, "The server port")
|
||||
)
|
||||
|
||||
|
@ -144,7 +144,6 @@ func (s *routeGuideServer) RouteChat(stream pb.RouteGuide_RouteChatServer) error
|
|||
key := serialize(in.Location)
|
||||
if _, present := s.routeNotes[key]; !present {
|
||||
s.routeNotes[key] = []*pb.RouteNote{in}
|
||||
|
||||
} else {
|
||||
s.routeNotes[key] = append(s.routeNotes[key], in)
|
||||
}
|
||||
|
@ -162,7 +161,7 @@ func (s *routeGuideServer) loadFeatures(filePath string) {
|
|||
if err != nil {
|
||||
log.Fatal("Failed to load default features: %v", err)
|
||||
}
|
||||
if err := json.Unmarshal(file, &(s.savedFeatures)); err != nil {
|
||||
if err := json.Unmarshal(file, &s.savedFeatures); err != nil {
|
||||
log.Fatal("Failed to load default features: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +215,7 @@ func serialize(point *pb.Point) string {
|
|||
func newServer() *routeGuideServer {
|
||||
s := new(routeGuideServer)
|
||||
s.loadFeatures(*jsonDBFile)
|
||||
s.routeNotes = make(map[string][]*pb.RouteNote, 0)
|
||||
s.routeNotes = make(map[string][]*pb.RouteNote)
|
||||
return s
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче