chore: 更新依赖、配置和代码生成
主要更新: - 更新 go.mod/go.sum 依赖 - 重新生成 Ent ORM 代码 - 更新 Wire 依赖注入配置 - 添加 docker-compose.override.yml 到 .gitignore - 更新 README 文档(Simple Mode 说明和已知问题) - 清理调试日志 - 其他代码优化和格式修复
This commit is contained in:
35
backend/internal/service/usage_clamp.go
Normal file
35
backend/internal/service/usage_clamp.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package service
|
||||
|
||||
import "time"
|
||||
|
||||
// clampInt 将整数限制在指定范围内
|
||||
func clampInt(value, min, max int) int {
|
||||
if value < min {
|
||||
return min
|
||||
}
|
||||
if value > max {
|
||||
return max
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// clampFloat64 将浮点数限制在指定范围内
|
||||
func clampFloat64(value, min, max float64) float64 {
|
||||
if value < min {
|
||||
return min
|
||||
}
|
||||
if value > max {
|
||||
return max
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// remainingSecondsUntil 计算到指定时间的剩余秒数,保证非负
|
||||
func remainingSecondsUntil(t time.Time) int {
|
||||
seconds := int(time.Until(t).Seconds())
|
||||
if seconds < 0 {
|
||||
return 0
|
||||
}
|
||||
return seconds
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user