1 package middleware_test 2 3 import ( 4 "bytes" 5 "net/http" 6 7 "edge-infra.dev/pkg/sds/emergencyaccess/middleware" 8 9 "github.com/gin-gonic/gin" 10 ) 11 12 // Gin context from handler function 13 var c *gin.Context 14 15 func ExampleSetLoggerInContext() { 16 // Running within gin handler function 17 18 // Create a new outgoing request as part of request handling 19 req, _ := http.NewRequestWithContext(c, "GET", "http://myservice", bytes.NewBuffer([]byte{})) 20 21 // Extract Correlation ID from context 22 correlationID := middleware.GetCorrelationID(c) 23 // Set correlation ID in appropriate header 24 req.Header.Set(middleware.CorrelationIDKey, correlationID) 25 26 // do request 27 } 28