updated hws.ThrowError to not return an error and log it to console instead
fixed errors_test fixed tests
This commit is contained in:
@@ -18,16 +18,24 @@ func startTimer(next http.Handler) http.Handler {
|
||||
)
|
||||
}
|
||||
|
||||
type contextKey string
|
||||
|
||||
func (c contextKey) String() string {
|
||||
return "hws context key " + string(c)
|
||||
}
|
||||
|
||||
var requestTimerCtxKey = contextKey("request-timer")
|
||||
|
||||
// Set the start time of the request
|
||||
func setStart(ctx context.Context, time time.Time) context.Context {
|
||||
return context.WithValue(ctx, "hws context key request-timer", time)
|
||||
return context.WithValue(ctx, requestTimerCtxKey, time)
|
||||
}
|
||||
|
||||
// Get the start time of the request
|
||||
func getStartTime(ctx context.Context) (time.Time, error) {
|
||||
start, ok := ctx.Value("hws context key request-timer").(time.Time)
|
||||
start, ok := ctx.Value(requestTimerCtxKey).(time.Time)
|
||||
if !ok {
|
||||
return time.Time{}, errors.New("Failed to get start time of request")
|
||||
return time.Time{}, errors.New("failed to get start time of request")
|
||||
}
|
||||
return start, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user