Skip to content

Commit

Permalink
Fix run and init server (#24)
Browse files Browse the repository at this point in the history
* Fix run and init server

* add codecov config

* fix code cov config
  • Loading branch information
crabio authored Aug 31, 2021
1 parent ce6f51f commit 6a4a8b2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
patch:
default:
target: 0%
project:
default:
target: 50%
13 changes: 6 additions & 7 deletions pkg/grpc_proxy_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func New(config *config.Config, grpcServer *grpc_server.Server, services []servi
return nil, err
}

// Create a client connection to the gRPC server
ps.grpcConn, err = ps.createGrpcProxyConnection()
if err != nil {
return nil, err
}

// Create mux router to route HTTP requests in server
mux := createGrpcProxyMuxServer()

Expand Down Expand Up @@ -95,13 +101,6 @@ func createGrpcProxyMuxServer() *runtime.ServeMux {

// Function runs gRPC proxy server on the [port]
func (ps *Server) Run() error {
var err error
// Create a client connection to the gRPC server
ps.grpcConn, err = ps.createGrpcProxyConnection()
if err != nil {
return err
}

go func() {
if err := ps.httpServer.ListenAndServe(); err != nil {
ps.log.WithError(err).Fatal("Couldn't serve gRPC-Gateway server")
Expand Down
2 changes: 2 additions & 0 deletions pkg/grpc_proxy_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestNew(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, grpcs)

assert.NoError(t, grpcs.Run())

s, err := grpc_proxy_server.New(c.Config, grpcs, []service.IServiceServer{})
assert.NoError(t, err)
assert.NotNil(t, s)
Expand Down
12 changes: 7 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,22 @@ func New(config *config.Config, externalServices []service.IServiceServer) (*Ser
return nil, fmt.Errorf("couldn't create gRPC server. " + err.Error())
}

s.grpcProxyServer, err = grpc_proxy_server.New(s.Config, s.grpcServer, s.services)
if err != nil {
return nil, fmt.Errorf("couldn't create gRPC proxy server. " + err.Error())
}

return s, nil
}

func (s *Server) Run() error {
var err error

// Run gRPC server before creating gRPC proxy to allow gRPC proxy dial connection with gRPC
if err := s.grpcServer.Run(); err != nil {
return fmt.Errorf("couldn't run gRPC server. " + err.Error())
}

// Init gRPC server proxy on run, because it can be inited only with working gRPC server
s.grpcProxyServer, err = grpc_proxy_server.New(s.Config, s.grpcServer, s.services)
if err != nil {
return fmt.Errorf("couldn't create gRPC proxy server. " + err.Error())
}
if err := s.grpcProxyServer.Run(); err != nil {
return fmt.Errorf("couldn't run gRPC proxy server. " + err.Error())
}
Expand Down

0 comments on commit 6a4a8b2

Please sign in to comment.