FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
slog/middleware.go at main · unrolled/slog · GitHub
This repository was archived by the owner on Dec 27, 2023. It is now read-only.
unrolled
/
slog
Public archive
Notifications
You must be signed in to change notification settings
Fork
1
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
slog
/
middleware.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (21 loc) · 729 Bytes
Breadcrumbs
slog
/
middleware.go
Copy path
File metadata and controls
27 lines (21 loc) · 729 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package
slog
import
"net/http"
var
(
// RequestHeaderKey is the key used when adding the header token.
RequestHeaderKey
=
"___slog_request_token___"
// RequestFieldKey is the key used in the Field output.
RequestFieldKey
=
"reqID"
// ResponseHeaderKey will send the token on the response as well (if set).
ResponseHeaderKey
=
""
)
// Requestify adds a unique key to the request (header) and uses it for logging.
func
Requestify
(
next
http.
Handler
) http.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http.
ResponseWriter
,
r
*
http.
Request
) {
token
:=
RequestToken
.
Generate
()
r
.
Header
.
Add
(
RequestHeaderKey
,
token
)
if
ResponseHeaderKey
!=
""
{
w
.
Header
().
Add
(
ResponseHeaderKey
,
token
)
}
next
.
ServeHTTP
(
w
,
r
)
})
}
Back
|
FazBrowse Home
|
New Git URL