mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
feat: add middleware for handling requests without cancel context
Introduced `GTagMiddlewarWithoutCancel` and `MPv2MiddlewarWithoutCancel` to allow handling of requests with contexts where cancellation signals are ignored. This improves flexibility for specific use cases where cancel propagation is not desired.
This commit is contained in:
parent
b2764d77d7
commit
07b186d846
@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -58,6 +59,12 @@ func GTagMiddlewarClientID(next GTagHandler) GTagHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GTagMiddlewarWithoutCancel(next GTagHandler) GTagHandler {
|
||||||
|
return func(r *http.Request, payload *gtag.Payload) error {
|
||||||
|
return next(r.WithContext(context.WithoutCancel(r.Context())), payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GTagMiddlewarSessionID(measurementID string) GTagMiddleware {
|
func GTagMiddlewarSessionID(measurementID string) GTagMiddleware {
|
||||||
measurementID = strings.Split(measurementID, "-")[1]
|
measurementID = strings.Split(measurementID, "-")[1]
|
||||||
return func(next GTagHandler) GTagHandler {
|
return func(next GTagHandler) GTagHandler {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -47,6 +48,12 @@ func MPv2MiddlewarDebugMode(next MPv2Handler) MPv2Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MPv2MiddlewarWithoutCancel(next MPv2Handler) MPv2Handler {
|
||||||
|
return func(r *http.Request, payload *mpv2.Payload[any]) error {
|
||||||
|
return next(r.WithContext(context.WithoutCancel(r.Context())), payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func MPv2MiddlewareUserID(cookieName string) MPv2Middleware {
|
func MPv2MiddlewareUserID(cookieName string) MPv2Middleware {
|
||||||
return func(next MPv2Handler) MPv2Handler {
|
return func(next MPv2Handler) MPv2Handler {
|
||||||
return func(r *http.Request, payload *mpv2.Payload[any]) error {
|
return func(r *http.Request, payload *mpv2.Payload[any]) error {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user