Added config options for http request timeouts
This commit is contained in:
@@ -8,4 +8,5 @@ func (c contextKey) String() string {
|
||||
|
||||
var (
|
||||
contextKeyAuthorizedUser = contextKey("auth-user")
|
||||
contextKeyRequestTime = contextKey("req-time")
|
||||
)
|
||||
|
||||
21
contexts/request_timer.go
Normal file
21
contexts/request_timer.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package contexts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Set the start time of the request
|
||||
func SetStart(ctx context.Context, time time.Time) context.Context {
|
||||
return context.WithValue(ctx, contextKeyRequestTime, time)
|
||||
}
|
||||
|
||||
// Get the start time of the request
|
||||
func GetStartTime(ctx context.Context) (time.Time, error) {
|
||||
start, ok := ctx.Value(contextKeyRequestTime).(time.Time)
|
||||
if !ok {
|
||||
return time.Time{}, errors.New("Failed to get start time of request")
|
||||
}
|
||||
return start, nil
|
||||
}
|
||||
Reference in New Issue
Block a user