Apply review suggestions
diff --git a/core/kg/server/grpc_server.go b/core/kg/server/grpc_server.go
index bc3b05f..565ce77 100644
--- a/core/kg/server/grpc_server.go
+++ b/core/kg/server/grpc_server.go
@@ -38,20 +38,17 @@
func (a *GRPCServerImpl) Start() error {
a.Log.Info("Starting GRPC Server...")
- // settings := model.NewConfig().SqlSettings
- // a.store = sqlstore.New(settings)
-
- lis, err := net.Listen("tcp", fmt.Sprintf(":%d", a.config.GRPCSettings.Port))
+ lis, err := net.Listen("tcp", fmt.Sprintf(":%d", a.config.GRPC.Port))
if err != nil {
- a.Log.Error("failed to listen: %v", log.Err(err))
+ a.Log.Error("Failed to listen: %v", log.Err(err))
return err
}
a.srv = grpc.NewServer()
- a.Log.Info("GRPC Server is listening on", log.Int("port", a.config.GRPCSettings.Port))
+ a.Log.Info("GRPC Server is listening on", log.Int("port", a.config.GRPC.Port))
if err := a.srv.Serve(lis); err != nil {
- a.Log.Error("failed to serve rpc: %v", log.Err(err))
+ a.Log.Error("Failed to serve rpc: %v", log.Err(err))
return err
}
return nil
diff --git a/core/kg/server/http_server.go b/core/kg/server/http_server.go
index e4a7688..6802332 100644
--- a/core/kg/server/http_server.go
+++ b/core/kg/server/http_server.go
@@ -44,16 +44,16 @@
a.Log.Info("Starting HTTP Server...")
a.srv = &http.Server{
- Addr: fmt.Sprintf("%s:%d", a.config.HTTPSettings.Host, a.config.HTTPSettings.Port),
+ Addr: fmt.Sprintf("%s:%d", a.config.HTTP.Host, a.config.HTTP.Port),
Handler: a.root,
- ReadTimeout: time.Duration(a.config.HTTPSettings.ReadTimeout) * time.Second,
- WriteTimeout: time.Duration(a.config.HTTPSettings.WriteTimeout) * time.Second,
- IdleTimeout: time.Duration(a.config.HTTPSettings.IdleTimeout) * time.Second,
+ ReadTimeout: time.Duration(a.config.HTTP.ReadTimeout) * time.Second,
+ WriteTimeout: time.Duration(a.config.HTTP.WriteTimeout) * time.Second,
+ IdleTimeout: time.Duration(a.config.HTTP.IdleTimeout) * time.Second,
}
- a.Log.Info("HTTP Server is listening on", log.Int("port", a.config.HTTPSettings.Port))
+ a.Log.Info("HTTP Server is listening on", log.Int("port", a.config.HTTP.Port))
if err := a.srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
- a.Log.Error("failed to listen and serve: %v", log.Err(err))
+ a.Log.Error("Failed to listen and serve: %v", log.Err(err))
return err
}
return nil
@@ -63,7 +63,7 @@
func (a *HTTPServerImpl) Shutdown() error {
a.Log.Info("Stopping HTTP Server...")
if a.srv == nil {
- return errors.New("no http server present")
+ return errors.New("No http server present")
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
diff --git a/core/kg/server/servers.go b/core/kg/server/servers.go
index d197666..7363a0e 100644
--- a/core/kg/server/servers.go
+++ b/core/kg/server/servers.go
@@ -2,9 +2,10 @@
import (
"os"
+ "os/signal"
+ "syscall"
"github.com/giolekva/pcloud/core/kg/log"
- "github.com/vardius/shutdown"
)
// Server interface
@@ -41,11 +42,17 @@
}
}(server)
}
- shutdown.GracefulStop(func() { ss.shutdown() })
+ // wait for kill signal before attempting to gracefully shutdown
+ // the running service
+ interruptChan := make(chan os.Signal, 1)
+ signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+ <-interruptChan
+ ss.logger.Info("os.Interrupt...")
+ ss.shutdown()
}
func (ss *Servers) shutdown() {
- ss.logger.Info("shutting down...")
+ ss.logger.Info("Shutting down...")
errCh := make(chan error, len(ss.servers))
@@ -58,12 +65,12 @@
for i := 0; i < len(ss.servers); i++ {
if err := <-errCh; err != nil {
go func(err error) {
- ss.logger.Error("shutdown error", log.Err(err))
+ ss.logger.Error("Shutdown error", log.Err(err))
os.Exit(1)
}(err)
return
}
}
- ss.logger.Info("gracefully stopped")
+ ss.logger.Info("Gracefully stopped")
}