support multi-module (#4)

* add multimodule
* re-package modules
This commit is contained in:
Ilia Denisov
2026-02-22 08:57:19 +02:00
committed by GitHub
parent 9e36d7151e
commit 8f982278d2
132 changed files with 317 additions and 191 deletions
+28
View File
@@ -0,0 +1,28 @@
package router
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
// LimitMiddleware limits number of concurrent connections using a buffered channel with limit spaces
func LimitMiddleware(limit int) gin.HandlerFunc {
if limit <= 0 {
panic("limit must be greater than 0")
}
semaphore := make(chan bool, limit)
t := time.NewTimer(time.Millisecond * 100)
return func(c *gin.Context) {
t.Reset(time.Millisecond * 100)
select {
case semaphore <- true:
c.Next()
<-semaphore
case <-t.C:
c.Status(http.StatusGatewayTimeout)
}
}
}