diff --git a/.env.example b/.env.example index 7b3caf4..b5071bb 100644 --- a/.env.example +++ b/.env.example @@ -6,9 +6,10 @@ DB_PORT = 5432 NGINX_PORT=8080 GOLANG_PORT=8888 +APP_ENV=localhost SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_SENDER_NAME="Go.Gin.Template " -SMTP_AUTH_EMAIL=caknocomel@gmail.com -SMTP_AUTH_PASSWORD=idrqtymakoopjqwy \ No newline at end of file +SMTP_AUTH_EMAIL= +SMTP_AUTH_PASSWORD= \ No newline at end of file diff --git a/main.go b/main.go index fec0b6e..4acda34 100644 --- a/main.go +++ b/main.go @@ -21,8 +21,15 @@ func main() { var ( db *gorm.DB = config.SetUpDatabaseConnection() jwtService service.JWTService = service.NewJWTService() + + // Implementation Dependency Injection + // Repository userRepository repository.UserRepository = repository.NewUserRepository(db) + + // Service userService service.UserService = service.NewUserService(userRepository, jwtService) + + // Controller userController controller.UserController = controller.NewUserController(userService) ) @@ -33,6 +40,7 @@ func main() { routes.User(server, userController, jwtService) var wg sync.WaitGroup + var serve string wg.Add(2) go func() { @@ -58,7 +66,13 @@ func main() { port = "8888" } - if err := server.Run("localhost:" + port); err != nil { + if os.Getenv("APP_ENV") == "localhost" { + serve = "127.0.0.1:" + port + } else { + serve = ":" + port + } + + if err := server.Run(serve); err != nil { log.Fatalf("error running server: %v", err) } }