mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-19 11:36:57 +00:00
Add reqId to all logging messages I could find (#413)
Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/413 Co-authored-by: crapStone <me@crapstone.dev> Co-committed-by: crapStone <me@crapstone.dev>
This commit is contained in:
parent
2438de0eb2
commit
ef7e2cd7bb
17 changed files with 88 additions and 54 deletions
|
@ -5,19 +5,29 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue