1 Star 0 Fork 0

sy_183 / go-common

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
size-out-of-range.go 938 Bytes
一键复制 编辑 原始数据 按行查看 历史
package errors
import (
"fmt"
"math"
)
type SizeOutOfRange struct {
Target string
MinSize int64
MaxSize int64
Size int64
RealSize bool
}
func NewSizeOutOfRange(target string, min, max, size int64, real bool) error {
return &SizeOutOfRange{Target: target, MinSize: min, MaxSize: max, Size: size, RealSize: real}
}
func (e *SizeOutOfRange) Error() string {
target := e.Target
if target == "" {
target = "数据"
}
var mode string
if e.RealSize {
mode = "实际"
} else {
mode = "已解析"
}
switch {
case e.MinSize == math.MinInt64:
return fmt.Sprintf("%s大小超过限制(,%d),%s大小为(%d)", e.Target, e.MaxSize, mode, e.Size)
case e.MaxSize == math.MaxInt64:
return fmt.Sprintf("%s大小超过限制(%d,),%s大小为(%d)", e.Target, e.MinSize, mode, e.Size)
default:
return fmt.Sprintf("%s大小超过限制(%d,%d),%s大小为(%d)", e.Target, e.MinSize, e.MaxSize, mode, e.Size)
}
}
1
https://gitee.com/sy_183/go-common.git
git@gitee.com:sy_183/go-common.git
sy_183
go-common
go-common
v1.0.4

搜索帮助

53164aa7 5694891 3bd8fe86 5694891