-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathserver.go
More file actions
33 lines (26 loc) · 706 Bytes
/
Copy pathserver.go
File metadata and controls
33 lines (26 loc) · 706 Bytes
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
package main
import (
"github.com/labstack/echo/v4"
"github.com/thoas/stats"
"net/http"
)
// Stats provides response time, status code count, etc.
var Stats = stats.New()
func main() {
r := echo.New()
r.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(ctx echo.Context) error {
beginning, recorder := Stats.Begin(ctx.Response().Writer)
err := next(ctx)
Stats.End(beginning, stats.WithRecorder(recorder))
return err
}
})
r.GET("/stats", func(ctx echo.Context) error {
return ctx.JSON(http.StatusOK, Stats.Data())
})
r.GET("/", func(ctx echo.Context) error {
return ctx.JSON(http.StatusOK, map[string]string{"hello": "world"})
})
r.Start("0.0.0.0:8080")
}