All Projects → gin-contrib → requestid

gin-contrib / requestid

Licence: MIT license
Request ID middleware for Gin Framework

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to requestid

go-gin-logrus
Gin Web Framework for using Logrus as the Gin logger with Tracing middleware
Stars: ✭ 38 (-66.96%)
Mutual labels:  gin, gin-middleware, gin-gonic
ginhelper
gin framework helper
Stars: ✭ 16 (-86.09%)
Mutual labels:  gin, gin-middleware, gin-gonic
httpsign
Signing HTTP Messages Middleware
Stars: ✭ 54 (-53.04%)
Mutual labels:  gin, gin-middleware, gin-gonic
go api boilerplate
🐶Go (Golang)🚀REST / GraphQL API + Postgres boilerplate
Stars: ✭ 127 (+10.43%)
Mutual labels:  gin, gin-gonic
logging
mod: zap logging in golang
Stars: ✭ 44 (-61.74%)
Mutual labels:  gin, gin-middleware
souin
An HTTP cache system, RFC compliant, compatible with @TykTechnologies, @traefik, @caddyserver, @go-chi, @bnkamalesh, @beego, @devfeel, @labstack, @gofiber, @go-goyave, @gin-gonic, @zalando, @zeromicro, @nginx and @apache
Stars: ✭ 269 (+133.91%)
Mutual labels:  gin-middleware, gin-gonic
logger
Gin middleware/handler to logger url path using rs/zerolog
Stars: ✭ 119 (+3.48%)
Mutual labels:  gin, gin-gonic
website
Official website and document for Gin
Stars: ✭ 88 (-23.48%)
Mutual labels:  gin, gin-gonic
go-12factor-example
Example the 12factor app using golang
Stars: ✭ 20 (-82.61%)
Mutual labels:  gin, gin-gonic
gin-rest-api
Example golang using gin framework everything you need, i create this tutorial special for beginner.
Stars: ✭ 56 (-51.3%)
Mutual labels:  gin, gin-gonic
go-gin-web-server
Deploy Go Gin on Render
Stars: ✭ 23 (-80%)
Mutual labels:  gin, gin-gonic
geo-smart-system
Open Source Realtime Tracking System
Stars: ✭ 36 (-68.7%)
Mutual labels:  gin, gin-gonic
gin-swagger
DRY templates for go-swagger
Stars: ✭ 79 (-31.3%)
Mutual labels:  gin, gin-gonic
Gin Swagger
gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
Stars: ✭ 2,001 (+1640%)
Mutual labels:  gin, gin-middleware
Go init
一个用go组织项目结构,主要包括 gin, goredis, gorm, websocket, rabbitmq等。👉
Stars: ✭ 183 (+59.13%)
Mutual labels:  gin
Nlpgnn
1. Use BERT, ALBERT and GPT2 as tensorflow2.0's layer. 2. Implement GCN, GAN, GIN and GraphSAGE based on message passing.
Stars: ✭ 221 (+92.17%)
Mutual labels:  gin
Goilerplate
Clean Boilerplate of Go, Domain-Driven Design, Clean Architecture, Gin and GORM.
Stars: ✭ 173 (+50.43%)
Mutual labels:  gin
Book
《Go 语言编程之旅:一起用 Go 做项目》本书涵盖细分为 5 + 1 板块,分别是命令行、HTTP、RPC、Websocket 应用、进程内缓存以及 Go 语言中的大杀器。
Stars: ✭ 167 (+45.22%)
Mutual labels:  gin
server-benchmarks
🚀 Cross-platform transparent benchmarks for HTTP/2 Web Servers at 2020-2023
Stars: ✭ 78 (-32.17%)
Mutual labels:  gin
Goview
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.
Stars: ✭ 213 (+85.22%)
Mutual labels:  gin

RequestID

Run Tests codecov Go Report Card GoDoc Join the chat at https://gitter.im/gin-gonic/gin

Request ID middleware for Gin Framework. Adds an indentifier to the response using the X-Request-ID header. Passes the X-Request-ID value back to the caller if it's sent in the request headers.

Config

define your custom generator function:

func main() {

  r := gin.New()

  r.Use(
    requestid.New(
      requestid.WithGenerator(func() string {
        return "test"
      }),
      requestid.WithCustomHeaderStrKey("your-customer-key"),
    ),
  )

  // Example ping request.
  r.GET("/ping", func(c *gin.Context) {
    c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
  })

  // Listen and Server in 0.0.0.0:8080
  r.Run(":8080")
}

Example

package main

import (
  "fmt"
  "net/http"
  "time"

  "github.com/gin-contrib/requestid"
  "github.com/gin-gonic/gin"
)

func main() {

  r := gin.New()

  r.Use(requestid.New())

  // Example ping request.
  r.GET("/ping", func(c *gin.Context) {
    c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
  })

  // Listen and Server in 0.0.0.0:8080
  r.Run(":8080")
}

How to get the request identifier:

// Example / request.
r.GET("/", func(c *gin.Context) {
  c.String(http.StatusOK, "id:"+requestid.Get(c))
})
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].