1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 04:21:57 +00:00

add experimental handlers examples

Former-commit-id: 8d8a0d15afce2554dc5926f6b9bd9c42cb95dad0
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-08-16 16:57:03 +03:00
parent db433f7dca
commit a7635afe62
21 changed files with 644 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
package main
import (
"github.com/kataras/iris"
"github.com/didip/tollbooth"
"github.com/iris-contrib/middleware/tollboothic"
)
// $ go get github.com/didip/tollbooth
// $ go run main.go
func main() {
app := iris.New()
limiter := tollbooth.NewLimiter(1, nil)
//
// or create a limiter with expirable token buckets
// This setting means:
// create a 1 request/second limiter and
// every token bucket in it will expire 1 hour after it was initially set.
// limiter := tollbooth.NewLimiter(1, &limiter.ExpirableOptions{DefaultExpirationTTL: time.Hour})
app.Get("/", tollboothic.LimitHandler(limiter), func(ctx iris.Context) {
ctx.HTML("<b>Hello, world!</b>")
})
app.Run(iris.Addr(":8080"))
}
// Read more at: https://github.com/didip/tollbooth