https://github.com/ibarryyan/beego-requestid
RequestId middleware for beego
https://github.com/ibarryyan/beego-requestid
beego requestid web
Last synced: 5 months ago
JSON representation
RequestId middleware for beego
- Host: GitHub
- URL: https://github.com/ibarryyan/beego-requestid
- Owner: ibarryyan
- License: mit
- Created: 2023-09-19T15:11:23.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-28T13:06:38.000Z (over 2 years ago)
- Last Synced: 2024-06-21T15:49:12.357Z (about 2 years ago)
- Topics: beego, requestid, web
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## beego-requestid
### Introduction
This is RequestId middleware for Beego Framework , It allows you to customize the way to obtain RequestId and generate RequestId.
### Download
```shell
go get -u github.com/ibarryyan/beego-requestid
```
### Example
```go
package main
import (
"log"
"time"
"github.com/spf13/cast"
"github.com/beego/beego"
"github.com/beego/beego/context"
beego_requestid "github.com/ibarryyan/beego-requestid"
)
func example1() {
beego.InsertFilter("/*", beego.BeforeRouter, beego_requestid.NewFilter())
beego.Get("/hello", func(c *context.Context) {
reqId := c.Request.Header.Get("X-Request-Id")
log.Printf("reqestid = %s", reqId)
_, _ = c.ResponseWriter.Write([]byte("hello..."))
return
})
beego.Run(":9900")
}
func example2() {
beego.InsertFilter("/*", beego.BeforeRouter, beego_requestid.NewFilter(
beego_requestid.WithGenRequestIdFunc(func() string {
return cast.ToString(time.Now().Unix())
}),
beego_requestid.WithHeaderReqIdKey("my_header_reqid"),
beego_requestid.WithCustomReqIdKey("my_reqid"),
))
beego.Get("/hello", func(c *context.Context) {
reqId := c.Request.Header.Get("my_header_reqid")
log.Printf("reqestid = %s", reqId)
cReqId := c.Input.GetData("my_reqid")
log.Printf("my reqestid = %s", cReqId)
_, _ = c.ResponseWriter.Write([]byte("hello..."))
return
})
beego.Run(":9900")
}
```
### LICENSE
MIT LICENSE
---
Thanks for your star ~