gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/errors/size-out-of-range.go (about) 1 package errors 2 3 import ( 4 "fmt" 5 "math" 6 ) 7 8 type SizeOutOfRange struct { 9 Target string 10 MinSize int64 11 MaxSize int64 12 Size int64 13 RealSize bool 14 } 15 16 func NewSizeOutOfRange(target string, min, max, size int64, real bool) error { 17 return &SizeOutOfRange{Target: target, MinSize: min, MaxSize: max, Size: size, RealSize: real} 18 } 19 20 func (e *SizeOutOfRange) Error() string { 21 target := e.Target 22 if target == "" { 23 target = "数据" 24 } 25 var mode string 26 if e.RealSize { 27 mode = "实际" 28 } else { 29 mode = "已解析" 30 } 31 switch { 32 case e.MinSize == math.MinInt64: 33 return fmt.Sprintf("%s大小超过限制(,%d),%s大小为(%d)", e.Target, e.MaxSize, mode, e.Size) 34 case e.MaxSize == math.MaxInt64: 35 return fmt.Sprintf("%s大小超过限制(%d,),%s大小为(%d)", e.Target, e.MinSize, mode, e.Size) 36 default: 37 return fmt.Sprintf("%s大小超过限制(%d,%d),%s大小为(%d)", e.Target, e.MinSize, e.MaxSize, mode, e.Size) 38 } 39 }