diff --git a/.gitignore b/.gitignore index ff9a24e..84b9370 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -cmd/cmd - # Binaries for programs and plugins *.exe *.exe~ @@ -18,4 +16,4 @@ vendor/ pgdata/ .vscode -__debug_bin \ No newline at end of file +__debug_bin diff --git a/config/config-local.yml b/config/config-local.yml index 299cf7c..3be1d3b 100644 --- a/config/config-local.yml +++ b/config/config-local.yml @@ -15,6 +15,8 @@ server: WriteTimeout: 5 CSRF: true Debug: false + StartHTTP: true + StartGRPC: true AccessLogDirectory: /var/log/power-sso/access.log ErrorLogDirectory: /var/log/power-sso/error.log PermissionBase: github.com/isaqueveras/power-sso diff --git a/config/model.go b/config/model.go index 80320c0..2291dc3 100644 --- a/config/model.go +++ b/config/model.go @@ -9,10 +9,10 @@ import ( ) const ( - // ModeDevelopment represents the development environment mode - ModeDevelopment string = "development" - // ModeDevelopment represents the production environment mode - ModeProduction string = "production" + // modeDevelopment represents the development environment mode + modeDevelopment string = "development" + // modeDevelopment represents the production environment mode + modeProduction string = "production" ) const ( @@ -56,6 +56,8 @@ type ( SSL bool CSRF bool Debug bool + StartHTTP bool + StartGRPC bool CtxDefaultTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration @@ -115,3 +117,13 @@ type ( Duration int64 } ) + +// IsModeDevelopment returns if in development mode +func (sc *ServerConfig) IsModeDevelopment() bool { + return sc.Mode == modeDevelopment +} + +// IsModeProduction returns if in production mode +func (sc *ServerConfig) IsModeProduction() bool { + return sc.Mode == modeProduction +} diff --git a/internal/application/auth/model.go b/internal/application/auth/model.go index 420e517..02dff09 100644 --- a/internal/application/auth/model.go +++ b/internal/application/auth/model.go @@ -78,7 +78,7 @@ func (rr *RegisterRequest) GeneratePassword() error { rr.RefreshTokenKey() cost := auth.CostHashPasswordDevelopment - if config.Get().Server.Mode == config.ModeProduction { + if config.Get().Server.IsModeProduction() { cost = auth.CostHashPasswordProduction } diff --git a/internal/server/grpc.go b/internal/server/grpc.go index 97debee..febff70 100644 --- a/internal/server/grpc.go +++ b/internal/server/grpc.go @@ -15,7 +15,6 @@ import ( gogrpc "google.golang.org/grpc" "google.golang.org/grpc/reflection" - "github.com/isaqueveras/power-sso/config" "github.com/isaqueveras/power-sso/internal/interface/grpc/auth" "github.com/isaqueveras/power-sso/internal/middleware" "github.com/isaqueveras/power-sso/pkg/logger" @@ -23,7 +22,9 @@ import ( ) func (s *Server) ServerGRPC() (err error) { - defer s.logg.Info("Server GRPC is running") + if !s.cfg.Server.StartGRPC { + return + } var ( listen net.Listener @@ -40,7 +41,8 @@ func (s *Server) ServerGRPC() (err error) { ) ) - if s.cfg.Server.Mode == config.ModeDevelopment { + s.logg.Info("Server GRPC is running") + if s.cfg.Server.IsModeDevelopment() { s.logg.Debug("RUNNING IN DEVELOPMENT: REFLECTION ON") reflection.Register(serverGRPC) } diff --git a/internal/server/rest.go b/internal/server/rest.go index 8e6f0cc..9946812 100644 --- a/internal/server/rest.go +++ b/internal/server/rest.go @@ -13,7 +13,6 @@ import ( "github.com/isaqueveras/endless" gopowersso "github.com/isaqueveras/go-powersso" - "github.com/isaqueveras/power-sso/config" "github.com/isaqueveras/power-sso/internal/interface/http/auth" "github.com/isaqueveras/power-sso/internal/interface/project" "github.com/isaqueveras/power-sso/internal/middleware" @@ -21,9 +20,12 @@ import ( ) func (s *Server) ServerHTTP() (err error) { - defer s.logg.Info("Server HTTP is running") + if !s.cfg.Server.StartHTTP { + return + } - if s.cfg.Server.Mode == config.ModeProduction { + s.logg.Info("Server HTTP is running") + if s.cfg.Server.IsModeProduction() { gin.SetMode(gin.ReleaseMode) } diff --git a/main.go b/main.go index 1658542..a1f4e8f 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,6 @@ func main() { server = server.NewServer(cfg, logg, group) ) - // TODO: add in the configuration if it is to run http server if err = server.ServerHTTP(); err != nil { logg.Fatal("Error while serving the server HTTP: ", err) } diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 34c8317..b4403f1 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -29,7 +29,7 @@ func NewLogger(cfg *config.Config) *Logger { func (l *Logger) InitLogger() { var cfg zap.Config - if l.cfg.Server.Mode != config.ModeDevelopment { + if !l.cfg.Server.IsModeDevelopment() { cfg = zap.NewProductionConfig() cfg.DisableStacktrace = true cfg.EncoderConfig = zap.NewProductionEncoderConfig() diff --git a/power-sso b/power-sso deleted file mode 100755 index 36bba53..0000000 Binary files a/power-sso and /dev/null differ