feat!: GetUUID returns a bool indicator if uuid is available
This commit is contained in:
parent
b9f84035b5
commit
f967f4f4a7
14
README.md
14
README.md
@ -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
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user