forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
31 lines (23 loc) · 770 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"github.com/kataras/iris/v12"
"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