2 Star 8 Fork 6

user_499098 / imgproxy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
timer.go 671 Bytes
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"context"
"fmt"
"time"
)
var timerSinceCtxKey = ctxKey("timerSince")
func setTimerSince(ctx context.Context) context.Context {
return context.WithValue(ctx, timerSinceCtxKey, time.Now())
}
func getTimerSince(ctx context.Context) time.Duration {
return time.Since(ctx.Value(timerSinceCtxKey).(time.Time))
}
func checkTimeout(ctx context.Context) {
select {
case <-ctx.Done():
d := getTimerSince(ctx)
if newRelicEnabled {
sendTimeoutToNewRelic(ctx, d)
}
if prometheusEnabled {
incrementPrometheusErrorsTotal("timeout")
}
panic(newError(503, fmt.Sprintf("Timeout after %v", d), "Timeout"))
default:
// Go ahead
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yunwisdoms/imgproxy.git
git@gitee.com:yunwisdoms/imgproxy.git
yunwisdoms
imgproxy
imgproxy
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891