Documentation
¶
Index ¶
Constants ¶
const DefaultHeaderKey = sdk.DefaultHeaderKey
DefaultHeaderKey is used by the middleware to extract the X-Diverge-Env header and inject it into the request context.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶
FromContext extracts the environment name from the context.
func PropagateEnvironment ¶
PropagateEnvironment returns middleware that propagates the x-diverge-env header from incoming requests to outgoing requests via the request context.
Example:
// Incoming handler:
mux.Use(divergehttp.PropagateEnvironment)
// Outgoing client:
client := &http.Client{
Transport: divergehttp.RoundTripper(http.DefaultTransport),
}
func PropagateEnvironmentWithOptions ¶ added in v0.7.0
PropagateEnvironmentWithOptions returns middleware with configurable extraction sources for the preview environment identifier.
Precedence: Header → Query Parameter → Subdomain (first match wins).
Example:
mux.Use(divergehttp.PropagateEnvironmentWithOptions(
divergehttp.WithBaseDomain("preview.example.com"),
divergehttp.WithQueryParams("x-diverge-env", "diverge_env"),
))
func RoundTripper ¶
func RoundTripper(base http.RoundTripper) http.RoundTripper
RoundTripper wraps an http.RoundTripper to inject x-diverge-env from context into outgoing HTTP requests.
Types ¶
type Option ¶ added in v0.7.0
type Option func(*middlewareConfig)
Option configures the middleware behavior.
func WithBaseDomain ¶ added in v0.7.0
WithBaseDomain configures subdomain-based environment extraction. For example, WithBaseDomain("preview.example.com") extracts "pr-123" from requests to "pr-123.preview.example.com".
func WithQueryParams ¶ added in v0.7.0
WithQueryParams configures query parameter keys to extract the environment from. For example, WithQueryParams("x-diverge-env", "diverge_env") checks both keys.
func WithStripQueryParam ¶ added in v0.7.0
WithStripQueryParam removes the matched query parameter from the URL after extraction. The request is cloned before mutation to prevent data races.
WARNING: Do not use with webhook handlers that verify HMAC signatures against the full URL — stripping parameters invalidates the signature.