diff --git a/.env.example b/.env.example index 7a62976..0769a0d 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ ENV=debug PORT=3000 SEED_DB=true +IS_RATE_LIMITER_ENABLED=true POSTGRES_URL=postgres://localhost/micrach \ No newline at end of file diff --git a/config/config.go b/config/config.go index f4f68b3..bfbafbd 100644 --- a/config/config.go +++ b/config/config.go @@ -7,9 +7,10 @@ import ( ) type AppConfig struct { - Env string - Port int - SeedDb bool + Env string + Port int + SeedDb bool + IsRateLimiterEnabled bool } type DbConfig struct { @@ -34,10 +35,14 @@ func getAppConfig() AppConfig { seedDbString := os.Getenv("SEED_DB") seedDb := seedDbString == "true" + isRateLimiterEnabledString := os.Getenv("IS_RATE_LIMITER_ENABLED") + isRateLimiterEnabled := isRateLimiterEnabledString == "true" + return AppConfig{ - Env: env, - Port: port, - SeedDb: seedDb, + Env: env, + Port: port, + SeedDb: seedDb, + IsRateLimiterEnabled: isRateLimiterEnabled, } } diff --git a/main.go b/main.go index 901cf78..0df9446 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,9 @@ func main() { router := gin.Default() router.LoadHTMLGlob("templates/*.html") router.ForwardedByClientIP = true - router.Use(middleware) + if Config.App.IsRateLimiterEnabled { + router.Use(middleware) + } router.Static("/uploads", "./uploads") router.Static("/static", "./static") router.GET("/", Controllers.GetThreads)