Skip to content

Commit

Permalink
Update xrpc RpcServer
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed Nov 29, 2023
1 parent 8ab8102 commit 9980667
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/xrpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ The necessary functions are encapsulated internally for unified management

```go
s := &xrpc.RpcServer{
Grpc: &xrpc.Grpc{
GrpcServer: &xrpc.GrpcServer{
Addr: "0.0.0.0:50000",
Registrar: func(s *grpc.Server) {
pb.RegisterOrderServer(s, &service{})
},
},
Gateway: &xrpc.Gateway{ // Optional
GatewayServer: &xrpc.GatewayServer{ // Optional
Addr: "0.0.0.0:50001",
Registrar: func(mux *runtime.ServeMux, conn *grpc.ClientConn) {
pb.RegisterOrderHandler(context.Background(), mux, conn)
Expand Down Expand Up @@ -145,13 +145,13 @@ if err != nil {
log.Fatal(err)
}
s := &xrpc.RpcServer{
Grpc: &xrpc.Grpc{
GrpcServer: &xrpc.GrpcServer{
Addr: "0.0.0.0:50000",
Registrar: func(s *grpc.Server) {
pb.RegisterOrderServer(s, &service{})
},
},
Gateway: &xrpc.Gateway{ // Optional
GatewayServer: &xrpc.GatewayServer{ // Optional
Addr: "0.0.0.0:50001",
Registrar: func(mux *runtime.ServeMux, conn *grpc.ClientConn) {
pb.RegisterOrderHandler(context.Background(), mux, conn)
Expand Down Expand Up @@ -181,7 +181,7 @@ Loggable Events

```go
s := &xrpc.RpcServer{
Grpc: &xrpc.Grpc{
GrpcServer: &xrpc.GrpcServer{
LoggableEvents: []logging.LoggableEvent{logging.StartCall, logging.FinishCall},
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/xrpc/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ func (t *RpcServer) Serve() error {
t.GatewayServer.Registrar(mux, conn)
requestLogger := func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Logger.Log(r.Context(), logging.LevelInfo, "gateway request", "method", r.Method, "path", r.URL.Path, "remote_addr", r.RemoteAddr)
next.ServeHTTP(w, r)
statusCode := w.(interface{ StatusCode() int }).StatusCode()
t.Logger.Log(r.Context(), logging.LevelInfo, "gateway request", "method", r.Method, "path", r.URL.Path, "remote_addr", r.RemoteAddr, "status_code", statusCode)
})
}
gateway := &http.Server{
Expand Down

0 comments on commit 9980667

Please sign in to comment.