...

Source file src/github.com/gin-contrib/requestid/_example/main.go

Documentation: github.com/gin-contrib/requestid/_example

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"net/http"
     7  	"time"
     8  
     9  	"github.com/gin-contrib/requestid"
    10  	"github.com/gin-gonic/gin"
    11  )
    12  
    13  func main() {
    14  	r := gin.New()
    15  
    16  	r.Use(requestid.New())
    17  
    18  	// Example ping request.
    19  	r.GET("/ping", func(c *gin.Context) {
    20  		c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
    21  	})
    22  
    23  	// Example / request.
    24  	r.GET("/", func(c *gin.Context) {
    25  		c.String(http.StatusOK, "id:"+requestid.Get(c))
    26  	})
    27  
    28  	// Listen and Server in 0.0.0.0:8080
    29  	if err := r.Run(":8080"); err != nil {
    30  		log.Fatal(err)
    31  	}
    32  }
    33  

View as plain text