Skip to content

Commit

Permalink
doc: get request_id from header (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfyiamcool authored Mar 24, 2024
1 parent 9b19025 commit 8344ce4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,29 @@ r.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "id:"+requestid.Get(c))
})
```

You can also get the request identifier from response header:

```
> curl -i "http://127.0.0.1:8080"
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
X-Request-ID: 77966910-3912-4193-9b74-267491c51700
Content-Length: 39
id:77966910-3912-4193-9b74-267491c51700
```

When http request with custom identifier, gin server return the custom identifier in response header.

```
> curl -i -H "X-Request-ID:test" "http://127.0.0.1:8080"
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
X-Request-Id: 1688221042
Content-Length: 13
id:test
```

0 comments on commit 8344ce4

Please sign in to comment.