add reqId to all logging messages I could find

This commit is contained in:
crapStone 2024-12-29 19:28:27 +01:00
parent 2438de0eb2
commit f87c692f7a
No known key found for this signature in database
GPG key ID: 22D4BF0CF7CC29C8
17 changed files with 89 additions and 54 deletions

View file

@ -5,19 +5,30 @@ import (
"net/http"
"codeberg.org/codeberg/pages/server/utils"
"github.com/hashicorp/go-uuid"
"github.com/rs/zerolog/log"
)
type Context struct {
RespWriter http.ResponseWriter
Req *http.Request
StatusCode int
ReqId string
}
func New(w http.ResponseWriter, r *http.Request) *Context {
req_uuid, err := uuid.GenerateUUID()
if err != nil {
log.Error().Err(err).Msg("Failed to generate request id, assigning error value")
req_uuid = "ERROR"
}
return &Context{
RespWriter: w,
Req: r,
StatusCode: http.StatusOK,
ReqId: req_uuid,
}
}