Apply commented improvements
- skip shutdown of gRPC server if failed to start - minor refactoring
This commit is contained in:
parent
def844c5fe
commit
38f8ff319e
2 changed files with 29 additions and 11 deletions
|
@ -10,17 +10,26 @@ type endpointsServer struct {
|
|||
}
|
||||
|
||||
func (e endpointsServer) GetEndpoints(_ context.Context, _ *GetEndpointsRequest) (*GetEndpointsResponse, error) {
|
||||
eps := make([]*Endpoint, 0)
|
||||
for _, ep := range e.endpointsManager.StartedEndpoints() {
|
||||
eps = append(eps, &Endpoint{
|
||||
eps := rpcEndpointsFromEndpoints(e.endpointsManager.StartedEndpoints())
|
||||
return &GetEndpointsResponse{
|
||||
Endpoints: *eps,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func rpcEndpointsFromEndpoints(eps []endpoints.Endpoint) *[]*Endpoint {
|
||||
out := make([]*Endpoint, 0)
|
||||
for _, ep := range eps {
|
||||
out = append(out, rpcEndpointFromEndpoint(ep))
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
func rpcEndpointFromEndpoint(ep endpoints.Endpoint) *Endpoint {
|
||||
return &Endpoint{
|
||||
Id: ep.Id().String(),
|
||||
Name: ep.Name(),
|
||||
Handler: ep.Handler(),
|
||||
ListenAddress: ep.Listen(),
|
||||
Port: int32(ep.Port()),
|
||||
})
|
||||
}
|
||||
return &GetEndpointsResponse{
|
||||
Endpoints: eps,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ type inetmockAPI struct {
|
|||
endpointManager endpoints.EndpointManager
|
||||
registry plugins.HandlerRegistry
|
||||
logger logging.Logger
|
||||
serverRunning bool
|
||||
}
|
||||
|
||||
func NewINetMockAPI(
|
||||
|
@ -56,6 +57,12 @@ func (i *inetmockAPI) StartServer() (err error) {
|
|||
}
|
||||
|
||||
func (i *inetmockAPI) StopServer() {
|
||||
if !i.serverRunning {
|
||||
i.logger.Info(
|
||||
"Skipping API server shutdown because server is not running",
|
||||
)
|
||||
return
|
||||
}
|
||||
gracefulStopChan := make(chan struct{})
|
||||
go func() {
|
||||
i.server.GracefulStop()
|
||||
|
@ -70,7 +77,9 @@ func (i *inetmockAPI) StopServer() {
|
|||
}
|
||||
|
||||
func (i *inetmockAPI) startServerAsync(listener net.Listener) {
|
||||
i.serverRunning = true
|
||||
if err := i.server.Serve(listener); err != nil {
|
||||
i.serverRunning = false
|
||||
i.logger.Error(
|
||||
"failed to start INetMock API",
|
||||
zap.Error(err),
|
||||
|
|
Loading…
Reference in a new issue