Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Throttle middleware #39

Merged
merged 1 commit into from
Feb 17, 2023
Merged

HTTP Throttle middleware #39

merged 1 commit into from
Feb 17, 2023

Conversation

hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Feb 17, 2023

The expected usage goal in goravel/goravel is:

  1. Add configureRateLimiting method and RateLimiter configurations to app/providers/route_service_provider.go
func (receiver *RouteServiceProvider) configureRateLimiting() {
	facades.RateLimiter.For("global", func(ctx contractshttp.Context) contractshttp.Limit {
		return limit.PerMinute(1)
	})
	facades.RateLimiter.ForWithLimits("upload", func(ctx contractshttp.Context) []contractshttp.Limit {
		return []contractshttp.Limit{limit.PerMinute(1), limit.PerDays(2, 3).By("1").Response(func(ctx contractshttp.Context) {
			ctx.Request().AbortWithStatusJson(499, contractshttp.Json{
				"Hi": "Goravel",
			})
		})}
	})
}
  1. Add middleware toroute/web.go
facades.Route.Middleware(middleware.Throttle("global"), middleware.Throttle("upload"))

@hwbrzzl hwbrzzl merged commit a4cd859 into master Feb 17, 2023
@hwbrzzl hwbrzzl deleted the bowen/throttle branch February 17, 2023 10:21
kkumar-gcc added a commit that referenced this pull request Oct 3, 2023
kkumar-gcc added a commit that referenced this pull request Nov 16, 2023


# Conflicts:
#	foundation/application_test.go
#	translation/file_loader_test.go
#	translation/message_selector.go
#	translation/translator_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant