global concurrent limiter
全局的并发请求限制,可以用于控制应用的并发请求量。
Example
package main
import (
"bytes"
"sync"
"time"
"github.com/vicanso/elton"
"github.com/vicanso/elton/middleware"
)
func main() {
e := elton.New()
e.Use(middleware.NewGlobalConcurrentLimiter(middleware.GlobalConcurrentLimiterConfig{
Max: 1000,
}))
e.POST("/login", func(c *elton.Context) (err error) {
time.Sleep(3 * time.Second)
c.BodyBuffer = bytes.NewBufferString("hello world")
return
})
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}