refactor: project code arch; feat: cancel operation anytime
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
package tool
|
||||
|
||||
import "github.com/loveuer/esgo2dump/internal/opt"
|
||||
|
||||
func Min[T ~string | ~int | ~int64 | ~uint64 | ~float64 | ~float32 | ~int32 | ~uint32 | ~int16 | ~uint16 | ~int8 | ~uint8](a, b T) T {
|
||||
if a <= b {
|
||||
return a
|
||||
@ -10,23 +8,14 @@ func Min[T ~string | ~int | ~int64 | ~uint64 | ~float64 | ~float32 | ~int32 | ~u
|
||||
return b
|
||||
}
|
||||
|
||||
func CalcSize(size, max, total int) int {
|
||||
fs := size
|
||||
if fs == 0 {
|
||||
fs = opt.DefaultSize
|
||||
}
|
||||
|
||||
func CalculateLimit(limit, total, max int) int {
|
||||
if max == 0 {
|
||||
return fs
|
||||
return limit
|
||||
}
|
||||
|
||||
if max > 0 && total >= max {
|
||||
return 0
|
||||
if max-total > 0 {
|
||||
return Min(max-total, limit)
|
||||
}
|
||||
|
||||
if max-total > fs {
|
||||
return max - total
|
||||
}
|
||||
|
||||
return fs
|
||||
return 0
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/loveuer/nf/nft/log"
|
||||
"github.com/loveuer/esgo2dump/pkg/log"
|
||||
)
|
||||
|
||||
func TablePrinter(data any, writers ...io.Writer) {
|
||||
|
15
internal/tool/validate.go
Normal file
15
internal/tool/validate.go
Normal file
@ -0,0 +1,15 @@
|
||||
package tool
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ValidScheme(scheme string) error {
|
||||
switch strings.ToLower(scheme) {
|
||||
case "http", "https":
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid scheme: %s", scheme)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user