You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/service/README.md
+13-5Lines changed: 13 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,12 +38,13 @@ type Config struct {
38
38
ErrorHandler *MiddlewareHandler //Optional. If true a handler will be added to the end of the chain.
39
39
}
40
40
41
-
//Handler will hold all the callback handlers to be registered. N.B. gin will be used.
41
+
//Handler will hold all the callback handlers to be registered. N.B. gin will be used.
42
42
type Handler struct {
43
-
Method string //HTTP method or service.AnyMethod to support all limits.
44
-
Path string //The path the endpoint runs on.
45
-
Group string //Optional - specify a group if this is to have it's own group. N.B. The point of the group is to allow middleware to run on some requests and not others(based on the group).
46
-
Handler func(c *gin.Context) //The handler to be used.
43
+
Method string // HTTP method or service.AnyMethod to support all limits.
44
+
Path string // The path the endpoint runs on.
45
+
Group string // Optional - specify a group (used to control which middlewares will run)
46
+
Handler func(c *gin.Context) // The handler to be used.
47
+
RateLimitConfig *HandlerRateLimitConfig // Optional rate limiting config specifically for the handler.
47
48
}
48
49
49
50
//MiddlewareHandler will hold all the middleware and whether
@@ -71,6 +72,12 @@ type CorsConfig struct {
71
72
Enabled bool //Whether CORS is enabled or not.
72
73
OverrideCfg *cors.Config //Optional. This is only required if you do not want to use the default CORS configuration.
73
74
}
75
+
76
+
// HandlerRateLimitConfig holds the rate limiting config fo a sepecific handler.
77
+
type HandlerRateLimitConfig struct {
78
+
Limit int // The number of requests allowed within the timeframe.
79
+
Within int // The timeframe(seconds) the requests are allowed in.
80
+
}
74
81
75
82
//Service will be the actual structure returned.
76
83
type Service struct {
@@ -82,6 +89,7 @@ type Service struct {
82
89
#### Notes
83
90
- The cors config and the handlers are based on the gin framework : https://github.com/gin-gonic/gin.
84
91
- Rate limiting is done by the library github.com/cnjack/throttle.
92
+
- Rate limiting can be added to a handler or on a per group basis.
85
93
- The group principle is based on Gin routergroups. The idea behind it is that not all middleware needs to run on
86
94
all requests so the middleware in a group will only run against an endpoint in that group.
87
95
This is applied to cors, rate limiting and any middleware in general.
0 commit comments