Skip to content

Commit

Permalink
feat: update env & structure
Browse files Browse the repository at this point in the history
  • Loading branch information
aarsxx committed Jun 30, 2024
1 parent 58114c5 commit 3bd4f6f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Example environment variables, update as needed
PORT=8000
DATABASE_URL=postgres://username:password@localhost:5432/otter?sslmode=disable
REDIS_URL=redis://localhost:6379/0
JWT_SECRET=your_jwt_secret
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USERNAME=your_username
SMTP_PASSWORD=your_password
TOKEN_TIMEOUT=7200
45 changes: 23 additions & 22 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
package main

import (
"github.com/gorilla/mux"
"gotter/internal/handlers"
"log"
"net/http"
"otter/configs"
"otter/internal/db"
"otter/internal/services"
"os"
"otter/config"
"otter/internal/adapters/api"
"otter/internal/adapters/db/postgres"
"otter/internal/adapters/db/redis"
"otter/internal/adapters/email"
"otter/internal/core/services"
)

func main() {
config := configs.LoadConfig()
config.LoadConfig()
db := postgres.NewPostgresDB(os.Getenv("DATABASE_URL"))
redisClient := redis.NewRedisClient(os.Getenv("REDIS_URL"))
emailService := email.NewSMTPService(
os.Getenv("SMTP_HOST"),
os.Getenv("SMTP_PORT"),
os.Getenv("SMTP_USERNAME"),
os.Getenv("SMTP_PASSWORD"),
)

dbConn, err := db.NewDBConnection(config.PostgresDSN)
if err != nil {
log.Fatalf("Could not connect to the database: %v", err)
}
userRepo := postgres.NewUserRepository(db)
sessionRepo := redis.NewSessionRepository(redisClient)

userService := services.NewUserService(dbConn)
resetService := services.NewResetService(dbConn)
deleteService := services.NewDeleteService(dbConn)
totpService := services.NewTOTPService(dbConn)
loginService := services.NewLoginService(dbConn, config.JwtSecret, config.TokenTimeout)
logoutService := services.NewLogoutService(dbConn)
authService := services.NewAuthService(userRepo, sessionRepo, emailService)
loginService := services.NewLoginService(userRepo, sessionRepo)
logoutService := services.NewLogoutService(sessionRepo)

r := mux.NewRouter()
handlers.RegisterHandlers(r, userService, resetService, deleteService, totpService, loginService, logoutService)

log.Printf("Server starting on %handlers:%handlers\n", config.ServiceAddr, config.ServicePort)
log.Fatal(http.ListenAndServe(config.ServiceAddr+":"+config.ServicePort, r))
router := api.NewRouter(authService, loginService, logoutService)
log.Fatal(router.Run(":8000"))
}
2 changes: 1 addition & 1 deletion configs/config.go → config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package configs
package config

import (
"os"
Expand Down

0 comments on commit 3bd4f6f

Please sign in to comment.