Spaces:
Runtime error
Runtime error
File size: 280 Bytes
215df2f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
package middlewares
import (
"github.com/gin-gonic/gin"
)
func MaxAllowed(n int) gin.HandlerFunc {
sem := make(chan struct{}, n)
acquire := func() { sem <- struct{}{} }
release := func() { <-sem }
return func(c *gin.Context) {
acquire()
defer release()
c.Next()
}
}
|