diff --git a/README.md b/README.md index d1956ad..cc4f927 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,19 @@ In other handlers you can access the UUID: ```golang 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 } ``` diff --git a/logginghandler.go b/logginghandler.go index fe79a01..eac7177 100644 --- a/logginghandler.go +++ b/logginghandler.go @@ -12,13 +12,13 @@ import ( ) // 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) if !ok { - return "" + return "", false } - return uuid.String() + return uuid.String(), true } // Logger returns a logger with the UUID set.