Refactor code to use 'any' type and improve context handling
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
24
server/handler/request_context.go
Normal file
24
server/handler/request_context.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultRequestTimeout = 2 * time.Minute
|
||||
reportRequestTimeout = 10 * time.Minute
|
||||
longRunningRequestTimeout = 2 * time.Hour
|
||||
)
|
||||
|
||||
func withRequestTimeout(r *http.Request, timeout time.Duration) (context.Context, context.CancelFunc) {
|
||||
base := context.Background()
|
||||
if r != nil {
|
||||
base = r.Context()
|
||||
}
|
||||
if timeout <= 0 {
|
||||
return base, func() {}
|
||||
}
|
||||
return context.WithTimeout(base, timeout)
|
||||
}
|
||||
Reference in New Issue
Block a user