From 46472d01fe15015bbc136c7e85b6140c4c89896d Mon Sep 17 00:00:00 2001 From: ericprd Date: Wed, 26 Feb 2025 22:50:13 +0800 Subject: [PATCH] fix: app port and check subscribe_plan_id --- config/conf.go | 3 +++ internal/config/chi_router.go | 2 +- internal/config/server.go | 4 ---- internal/services/auth/register_user.go | 10 +++++++--- 4 files changed, 11 insertions(+), 8 deletions(-) delete mode 100644 internal/config/server.go diff --git a/config/conf.go b/config/conf.go index 1723f54..50bd012 100644 --- a/config/conf.go +++ b/config/conf.go @@ -20,4 +20,7 @@ func InitEnv() { DB_PASSWORD = utils.GetOrDefault("DB_PASSWORD", "") DB_NAME = utils.GetOrDefault("DB_NAME", "") DB_PORT = utils.GetOrDefault("DB_PORT", "") + + APP_PORT = utils.GetOrDefault("APP_PORT", 3000) + GRACEFULL_TIMEOUT = utils.GetOrDefault("GRACEFULL_TIMEOUT", 10) } diff --git a/internal/config/chi_router.go b/internal/config/chi_router.go index 203c8bd..d8464bf 100644 --- a/internal/config/chi_router.go +++ b/internal/config/chi_router.go @@ -22,7 +22,7 @@ func Router(apiRouter chi.Router) { defer stop() svr := &http.Server{ - Addr: fmt.Sprintf(":%d", APP_PORT), + Addr: fmt.Sprintf(":%d", config.APP_PORT), Handler: mainRouter, } diff --git a/internal/config/server.go b/internal/config/server.go deleted file mode 100644 index 5254372..0000000 --- a/internal/config/server.go +++ /dev/null @@ -1,4 +0,0 @@ -package pkgconfig - -const APP_PORT = 3000 -const GRACEFULL_TIMEOUT = 20 diff --git a/internal/services/auth/register_user.go b/internal/services/auth/register_user.go index 402e947..7432179 100644 --- a/internal/services/auth/register_user.go +++ b/internal/services/auth/register_user.go @@ -15,9 +15,13 @@ func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error) return "", errors.New("this email address is already in use") } - subsId, err := a.subsRepo.Create(spec.SubscribePlanID) - if err != nil { - return "", nil + var subsId string + + if spec.SubscribePlanID != "" { + subsId, err = a.subsRepo.Create(spec.SubscribePlanID) + if err != nil { + return "", nil + } } hashedPwd, err := HashPassword(spec.Password)