Skip to content

Wr4thon/requestid

Repository files navigation

requestid

Description

this repository is a collection of middlewares, used to get a requestID from an http request, and set it in rest clients used to perform requests.

supported frameworks

FrameworkSupportVersion
Restyv2
Echov4
Atreugov10

how to install

go get github.com/Wr4thon/[email protected]

How to use

resty

package main import ( "context""github.com/Wr4thon/requestid""github.com/go-resty/resty/v2" ) funcmain(){client:=resty. New(). OnBeforeRequest(requestid.RestyMiddleware) // this most likely will be set by an http framework such as atreugo or echo.ctx:=context.TODO() ctx=requestid.Set(ctx, "<TheRequestID>") resp, err:=client.R(). SetContext(ctx). Get("https://example.com") iferr!=nil{panic(err) } println(string(resp.Body())) }

echo

package main import ( "net/http""github.com/Wr4thon/requestid""github.com/labstack/echo/v4""github.com/labstack/echo/v4/middleware" ) funcmain(){e:=echo.New() e.Use(middleware.RequestID()) e.Use(requestid.EchoMiddleware()) e.GET("/", func(c echo.Context) error{rid, err:=requestid.Get(c.Request().Context()) iferr!=nil{println(err.Error()) returnc.NoContent(http.StatusInternalServerError) } println(rid) returnc.NoContent(http.StatusNoContent) }) e.Logger.Error(e.Start(":1337")) }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages