Skip to content

Commit

Permalink
fixup! Lets example servers gracefully shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
yugui committed Apr 22, 2018
1 parent 46d62a3 commit d2f6566
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 13 deletions.
2 changes: 2 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ go_test(
"//examples/server:go_default_library",
"//examples/sub:go_default_library",
"//runtime:go_default_library",
"@com_github_golang_glog//:go_default_library",
"@com_github_golang_protobuf//jsonpb:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//ptypes/empty:go_default_library",
"@org_golang_google_genproto//googleapis/rpc/status:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_x_net//context:go_default_library",
],
)
11 changes: 0 additions & 11 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ func preflightHandler(w http.ResponseWriter, r *http.Request) {
return
}

func newGateway(ctx context.Context, opts ...runtime.ServeMuxOption) (http.Handler, error) {
switch *network {
case "tcp":
return gateway.NewTCPGateway(ctx, *endpoint, opts...)
case "unix":
return gateway.NewUnixGateway(ctx, *endpoint, opts...)
default:
return nil, fmt.Errorf("unsupported network type %q:", *network)
}
}

// Run starts a HTTP server and blocks forever if successful.
func Run(ctx context.Context, address string, opts ...runtime.ServeMuxOption) error {
ctx, cancel := context.WithCancel(ctx)
Expand Down
2 changes: 1 addition & 1 deletion examples/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func runServers(ctx context.Context) <-chan error {
ch := make(chan error, 2)
go func() {
if err := server.Run(ctx, *network, *endpoint); err != nil {
if err := server.Run(ctx); err != nil {
ch <- fmt.Errorf("cannot run grpc service: %v", err)
}
}()
Expand Down
1 change: 1 addition & 0 deletions examples/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ go_library(
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//metadata:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
"@org_golang_x_net//context:go_default_library",
],
)
2 changes: 1 addition & 1 deletion examples/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Run(ctx context.Context) error {
}
defer func() {
if err := l.Close(); err != nil {
glog.Errorf("Failed to close %s %s: %v", network, address, err)
glog.Errorf("Failed to close tcp :9090: %v", err)
}
}()

Expand Down

0 comments on commit d2f6566

Please sign in to comment.