feat!: GetUUID returns a bool indicator if uuid is available
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing

This commit is contained in:
Marvin Preuss 2022-01-20 13:11:46 +01:00
parent b9f84035b5
commit f967f4f4a7
2 changed files with 16 additions and 4 deletions

View File

@ -58,7 +58,19 @@ In other handlers you can access the UUID:
```golang ```golang
func anotherHandler(w http.ResponseWriter, r *http.Request) { func anotherHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "your uuid is: %s", logginghandler.GetUUID(r)) log := logginghandler.Logger(r)
uuid, ok := logginghandler.GetUUID(r)
if !ok {
log.Error().Err(err).Msg("could not find uuid")
w.WriteHeader(http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "your uuid is: %s", uuid)
return
} }
``` ```

View File

@ -12,13 +12,13 @@ import (
) )
// GetUUID gets the requests UUID from a request. // GetUUID gets the requests UUID from a request.
func GetUUID(r *http.Request) string { func GetUUID(r *http.Request) (string, bool) {
uuid, ok := hlog.IDFromRequest(r) uuid, ok := hlog.IDFromRequest(r)
if !ok { if !ok {
return "" return "", false
} }
return uuid.String() return uuid.String(), true
} }
// Logger returns a logger with the UUID set. // Logger returns a logger with the UUID set.