Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const DefaultHeader = header.XRequestID
DefaultHeader is the default request, response header
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RequestID ¶
type RequestID struct {
// TrustProxy trusts request id from request header
// sets TrustProxy to false for always generate new request id
TrustProxy bool
// Header is the http header key
Header string
}
RequestID middleware
Example ¶
At the edge, do not trust a client-supplied request ID: always mint a new one so callers cannot spoof or poison the value used in logs and upstream headers. A custom header key is used here instead of the default X-Request-Id.
package main
import (
"github.com/moonrhythm/parapet"
"github.com/moonrhythm/parapet/pkg/requestid"
)
func main() {
s := parapet.New()
s.Use(&requestid.RequestID{
TrustProxy: false,
Header: "X-Trace-Id",
})
}
Output:
func New ¶
func New() *RequestID
New creates default req id middleware
Example ¶
Assign every request a unique ID. New trusts an incoming X-Request-Id from an upstream proxy (reusing it for distributed tracing) and otherwise generates a fresh UUIDv4. The ID is written to both the request and response headers and recorded as "requestId" in the structured access log.
package main
import (
"github.com/moonrhythm/parapet"
"github.com/moonrhythm/parapet/pkg/requestid"
)
func main() {
s := parapet.New()
s.Use(requestid.New())
// s.Use(upstream.SingleHost(...)) — the ID is forwarded to the upstream.
}
Output:
Click to show internal directories.
Click to hide internal directories.