Skip to content

Commit

Permalink
fix:add already local service check to avoid panic
Browse files Browse the repository at this point in the history
  • Loading branch information
geebytes committed Jun 1, 2024
1 parent 1c000e8 commit db00cd9
Show file tree
Hide file tree
Showing 3 changed files with 309 additions and 295 deletions.
4 changes: 4 additions & 0 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (g *GatewayServer) RegisterService(ctx context.Context, pd ProtobufDescript
return g.httpGateway.RegisterHandlerClient(ctx, pd, g.gatewayMux)
}
func (g *GatewayServer) RegisterLocalService(ctx context.Context, pd ProtobufDescription, sd *grpc.ServiceDesc, ss any) error {
info:=g.grpcServer.GetServiceInfo()
if _,ok:=info[sd.ServiceName];ok{
return fmt.Errorf("service %s already exists",sd.ServiceName)
}
g.grpcServer.RegisterService(sd, ss)
return g.httpGateway.RegisterHandlerClient(ctx, pd, g.gatewayMux)
}
Expand Down
4 changes: 4 additions & 0 deletions gateway/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ func testRegisterLocalService(t *testing.T) {
c.So(rsp.Message, c.ShouldEqual, "hello")
c.So(rsp.Name, c.ShouldEqual, "world")

err = localGW.RegisterLocalService(context.Background(), pd, exampleServer.Desc(), exampleServer)
c.So(err, c.ShouldNotBeNil)
c.So(err.Error(), c.ShouldContainSubstring, "already exists")

})
c.Convey("test del local service", t, func() {
localGW.DeleteLocalService(pd)
Expand Down
Loading

0 comments on commit db00cd9

Please sign in to comment.