Skip to content

Commit 203194b

Browse files
authored
Update README.md
1 parent 425dbef commit 203194b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ api.Use(func(ctx *rest.Context) {
2121
ctx.Set("authtoken", "roshangade")
2222
})
2323
24+
// hooks support on request pre-send or post-send
25+
// ctx.PreSend(func() error) OR ctx.PostSend(func() error)
26+
api.Use(func(ctx *rest.Context) {
27+
s := time.Now().UnixNano()
28+
ctx.PreSend(func() error {
29+
x := time.Now().UnixNano() - s
30+
ctx.SetHeader("x-runtime", strconv.FormatInt(x/int64(time.Millisecond), 10))
31+
return nil
32+
})
33+
})
34+
35+
2436
// routes
2537
api.Get("/", func(ctx *rest.Context) {
2638
ctx.Text("Hello World!")

0 commit comments

Comments
 (0)