Skip to content

LipingMao/trackingId

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trackingId

Gin trackingId Middleware, if the Request has Tracking-Id already, just store it in context, if it does not have Tracking-Id header, generate a new one with Google uuid.

How to use

With default header "Tracking-Id"

import (
    ...
    "github.com/gin-gonic/gin"
    "github.com/LipingMao/trackingId"
    ...
)

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

    // Load middleware
    r.Use(trackingId.TrackingId())

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

    // Start server
    r.Run()
}

With Customized Header

import (
    ...
    "github.com/gin-gonic/gin"
    "github.com/LipingMao/trackingId"
    ...
)

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

    // Load middleware
    r.Use(trackingId.TrackingIdWithCustomizedHeader("X-Track-ID"))

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

    // Start server
    r.Run()
}

About

Gin TrackingId Middleware

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages