File tree 3 files changed +21
-0
lines changed
3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ type Config struct {
47
47
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
48
48
BleveDir string `json:"bleve_dir" env:"BLEVE_DIR"`
49
49
Log LogConfig `json:"log"`
50
+ MaxConnections int `json:"max_connections" env:"MAX_CONNECTIONS"`
50
51
}
51
52
52
53
func DefaultConfig () * Config {
@@ -74,5 +75,6 @@ func DefaultConfig() *Config {
74
75
MaxBackups : 5 ,
75
76
MaxAge : 28 ,
76
77
},
78
+ MaxConnections : 0 ,
77
79
}
78
80
}
Original file line number Diff line number Diff line change
1
+ package middlewares
2
+
3
+ import (
4
+ "github.com/gin-gonic/gin"
5
+ )
6
+
7
+ func MaxAllowed (n int ) gin.HandlerFunc {
8
+ sem := make (chan struct {}, n )
9
+ acquire := func () { sem <- struct {}{} }
10
+ release := func () { <- sem }
11
+ return func (c * gin.Context ) {
12
+ acquire ()
13
+ defer release ()
14
+ c .Next ()
15
+ }
16
+ }
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ func Init(r *gin.Engine) {
16
16
common .SecretKey = []byte (conf .Conf .JwtSecret )
17
17
Cors (r )
18
18
r .Use (middlewares .StoragesLoaded )
19
+ if conf .Conf .MaxConnections > 0 {
20
+ r .Use (middlewares .MaxAllowed (conf .Conf .MaxConnections ))
21
+ }
19
22
WebDav (r .Group ("/dav" ))
20
23
21
24
r .GET ("/favicon.ico" , handles .Favicon )
You can’t perform that action at this time.
0 commit comments