Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 16, 2020. It is now read-only.

Concurrent limiter middleware for elton.

License

NotificationsYou must be signed in to change notification settings

vicanso/elton-concurrent-limiter

Repository files navigation

The middleware has been archived, please use the middleware ofelton.

Build Status

Concurrent limiter for elton. It support to get lock value from five ways.Client IP,QueryString,Request Header,Route Params andPost Body.

  • IP The key's name is:ip
  • QueryString The key's name has prefixq:
  • Request Header The key's name has prefixh:
  • Route Params The key's name has prefixp:
  • Post Body The other's key
package mainimport ("bytes""sync""time""github.com/vicanso/elton"concurrentLimiter"github.com/vicanso/elton-concurrent-limiter")funcmain() {e:=elton.New()m:=new(sync.Map)limit:=concurrentLimiter.New(concurrentLimiter.Config{Keys: []string{":ip","h:X-Token","q:type","p:id","account",},Lock:func(keystring,c*elton.Context) (successbool,unlockfunc(),errerror) {_,loaded:=m.LoadOrStore(key,true)// the key not existsif!loaded {success=trueunlock=func() {m.Delete(key)}}return},})e.POST("/login",limit,func(c*elton.Context) (errerror) {time.Sleep(3*time.Second)c.BodyBuffer=bytes.NewBufferString("hello world")return})err:=e.ListenAndServe(":3000")iferr!=nil {panic(err)})}
curl -XPOST'http://127.0.0.1:7001/login'

About

Concurrent limiter middleware for elton.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp