Skip to content
Gingonic X-Request-Id middleware
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Gingonic X-Request-Id middleware

Basic middleware to add and expose an UUID4 for each request based on the code posted on Dan Sosedoff development and experiments website.

It will set the variable RequestId or order to use it from within the application for logging or propagation.

If X-Request-Id header is sent in the request, it will set that value as RequestId.


Use go get to fetch the package:

$ go get


Import it and use it in your router:

import (

func main() {
    // Initialize router
    r := gin.Default()

    // Load middleware

    // Your routes
    r.GET("/ping", func(c *gin.Context) {
        c.String(200, "pong")

    // Start server

Check if it's working:

$ curl --verbose localhost:8080/ping
*   Trying
* Connected to localhost ( port 8080 (#0)
> GET /ping HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
< HTTP/1.1 200 OK
< Content-Type: text/plain; charset=utf-8
< X-Request-Id: 3528d29d-f5c6-4758-ae05-eee5a56c27ea
< Date: Wed, 25 Jan 2017 12:42:30 GMT
< Content-Length: 4
* Connection #0 to host localhost left intact

Use it for logging::

r.GET("/ping", func(c *gin.Context) {
    fmt.Println(fmt.Sprintf("[request-id:%s][event:ping]", c.MustGet("RequestId")))
    c.String(200, "pong")


0.0.2 - 2018-03-06

  • Fix for change in signature in the main dependecy of the package. In order to use the last version of update to 0.0.2 version.

0.0.1 - 2017-02-07

  • Initial release, basic middleware. It works!


Andres Tarantini (


GNU GPL v3. See LICENSE file.

You can’t perform that action at this time.