-
Notifications
You must be signed in to change notification settings - Fork 91
/
main.go
51 lines (40 loc) · 1.41 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"github.com/kataras/iris/v12"
"github.com/iris-contrib/middleware/expmetric"
)
func main() {
// Initialization of the Iris web application.
app := iris.New()
// To capture all hits (including not found pages and all routes)
// register the middleware using the UseRouter wrapper like this:
// app.UseRouter(expmetric.HitsPerMinute())
// Rregister the handler to list the expvars.
//
// Note: Register it after the middleware if you want to capture
// the hits of the /debug/vars page as well.
//
// Tip: you can protect this endpoint with basic authentication.
app.Get("/debug/vars", expmetric.Handler())
// app.Get("/", expmetric.HitsPerMinute(), index)
// To capture hits per group of routes:
// usersRouter := app.Party("/users")
// usersRouter.Use(expmetric.HitsPerMinute())
// To register the middleware only on the below routes (e.g. / -> index):
// app.Use(expmetric.HitsPerMinute())
// HitsPerSecond
// HitsPerHour
// HitsTotal
app.Use(expmetric.HitsTotal())
// To capture hits on specific endpoint just
// add it before the main route's handler:
app.Get("/", expmetric.HitsPerMinute(expmetric.MetricName("hits_minute")), helloWorld)
// More options and listening.
//
// Navigate to http://localhost:8080 and
// then to http://localhost:8080/debug/vars
app.Listen(":8080")
}
func helloWorld(ctx iris.Context) {
ctx.WriteString("Hello, World!")
}