router concurrent limiter
路由限制中间件,可以指定路由的并发访问数量,建议使用NewLocalLimiter
每个实例的限制分开,主要是用于避免某个接口并发过高导致系统不稳定。
Example
package main
import (
"bytes"
"time"
"github.com/vicanso/elton"
"github.com/vicanso/elton/middleware"
)
func main() {
e := elton.New()
e.Use(middleware.NewRCL(middleware.RCLConfig{
Limiter: middleware.NewLocalLimiter(map[string]uint32{
"GET /users/me": 2,
}),
}))
e.GET("/users/me", func(c *elton.Context) (err error) {
time.Sleep(time.Second)
c.BodyBuffer = bytes.NewBufferString(`{
"account": "tree",
"name": "tree.xie"
}`)
return nil
})
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}