This repository was archived by the owner on Apr 16, 2020. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork0
Concurrent limiter middleware for elton.
License
NotificationsYou must be signed in to change notification settings
vicanso/elton-concurrent-limiter
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The middleware has been archived, please use the middleware ofelton.
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.