global concurrent limiter

全局的并发请求限制,可以用于控制应用的并发请求量。

Example

  1. package main
  2. import (
  3. "bytes"
  4. "sync"
  5. "time"
  6. "github.com/vicanso/elton"
  7. "github.com/vicanso/elton/middleware"
  8. )
  9. func main() {
  10. e := elton.New()
  11. e.Use(middleware.NewGlobalConcurrentLimiter(middleware.GlobalConcurrentLimiterConfig{
  12. Max: 1000,
  13. }))
  14. e.POST("/login", func(c *elton.Context) (err error) {
  15. time.Sleep(3 * time.Second)
  16. c.BodyBuffer = bytes.NewBufferString("hello world")
  17. return
  18. })
  19. err := e.ListenAndServe(":3000")
  20. if err != nil {
  21. panic(err)
  22. }
  23. }