diff --git a/analyze.go b/analyze.go index c319f53..379796a 100644 --- a/analyze.go +++ b/analyze.go @@ -23,7 +23,7 @@ func (t *Teler) Analyze(w http.ResponseWriter, r *http.Request) error { // If threat detected, set teler request ID to the header if err != nil { - setReqIdHeader(w) + setCustomHeader(w, xTelerReqId, getUID()) } return err diff --git a/teler.go b/teler.go index 45f8596..7102a1d 100644 --- a/teler.go +++ b/teler.go @@ -358,15 +358,16 @@ func (t *Teler) postAnalyze(w http.ResponseWriter, r *http.Request, k threat.Thr return } - // Set teler request ID to the header - id := setReqIdHeader(w) + // Get unique ID + id := getUID() // Get the error message & convert to string as a message msg := err.Error() - // Set custom headers ("X-Teler-Msg" and "X-Teler-Threat") + // Set custom headers ("X-Teler-Msg", "X-Teler-Threat", "X-Teler-Req-Id") setCustomHeader(w, xTelerMsg, msg) setCustomHeader(w, xTelerThreat, k.String()) + setCustomHeader(w, xTelerReqId, id) // Send the logs t.sendLogs(r, k, id, msg) diff --git a/utils.go b/utils.go index a6b36f8..59a103f 100644 --- a/utils.go +++ b/utils.go @@ -211,14 +211,11 @@ func setCustomHeader(w http.ResponseWriter, key, value string) { w.Header().Set(key, value) } -// setReqIdHeader to set teler request ID header response and return it -func setReqIdHeader(w http.ResponseWriter) string { +// getUID to get unique ID +func getUID() string { // Generate a unique ID using the gouid package. id := gouid.Bytes(10) - // Set the "X-Teler-Req-Id" header in the response with the unique ID. - setCustomHeader(w, xTelerReqId, id.String()) - return id.String() }