mirror of https://github.com/zhufuyi/sponge
style: fix ci-lint
This commit is contained in:
parent
6c4ce7e6f9
commit
65e013ee3e
|
@ -5,11 +5,11 @@ import "strings"
|
||||||
var defaultMaxSize = 1000
|
var defaultMaxSize = 1000
|
||||||
|
|
||||||
// SetMaxSize change the default maximum number of pages per page
|
// SetMaxSize change the default maximum number of pages per page
|
||||||
func SetMaxSize(max int) {
|
func SetMaxSize(maxValue int) {
|
||||||
if max < 10 {
|
if maxValue < 10 {
|
||||||
max = 10
|
maxValue = 10
|
||||||
}
|
}
|
||||||
defaultMaxSize = max
|
defaultMaxSize = maxValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Page info
|
// Page info
|
||||||
|
|
|
@ -95,13 +95,13 @@ func handleExec(ctx context.Context, cmd *exec.Cmd, result *Result) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCmdReader(cmd *exec.Cmd) (io.ReadCloser, io.ReadCloser, error) {
|
func getCmdReader(cmd *exec.Cmd) (stdout io.ReadCloser, stderr io.ReadCloser, err error) {
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err = cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr, err := cmd.StderrPipe()
|
stderr, err = cmd.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,17 @@ func GetFilenameWithoutSuffix(filePath string) string {
|
||||||
return strings.TrimSuffix(name, path.Ext(name))
|
return strings.TrimSuffix(name, path.Ext(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRelativeFilePath get relative file path, force to use "/" as separator
|
||||||
|
func GetRelativeFilePath(absFilePath string) string {
|
||||||
|
dirPath, _ := filepath.Abs(".")
|
||||||
|
dirPath = filepath.ToSlash(filepath.Clean(dirPath))
|
||||||
|
absFilePath = filepath.ToSlash(filepath.Clean(absFilePath))
|
||||||
|
if !strings.HasSuffix(dirPath, "/") {
|
||||||
|
dirPath += "/"
|
||||||
|
}
|
||||||
|
return strings.TrimPrefix(absFilePath, dirPath)
|
||||||
|
}
|
||||||
|
|
||||||
// Join joins any number of path elements into a single path
|
// Join joins any number of path elements into a single path
|
||||||
func Join(elem ...string) string {
|
func Join(elem ...string) string {
|
||||||
dir := strings.Join(elem, "/")
|
dir := strings.Join(elem, "/")
|
||||||
|
|
|
@ -105,6 +105,9 @@ func TestGetFilename(t *testing.T) {
|
||||||
|
|
||||||
name = GetFilenameWithoutSuffix("./README.md")
|
name = GetFilenameWithoutSuffix("./README.md")
|
||||||
assert.Equal(t, "README", name)
|
assert.Equal(t, "README", name)
|
||||||
|
|
||||||
|
fp := GetRelativeFilePath("/user/sponge/pkg/gofile/testDir/test.txt")
|
||||||
|
assert.Contains(t, fp, "testDir/test.txt")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetPathDelimiter(t *testing.T) {
|
func TestGetPathDelimiter(t *testing.T) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ type circuitBreakerOptions struct {
|
||||||
validCodes map[codes.Code]struct{}
|
validCodes map[codes.Code]struct{}
|
||||||
|
|
||||||
// degrade handler for unary server
|
// degrade handler for unary server
|
||||||
unaryServerDegradeHandler func(ctx context.Context, req interface{}) (reply interface{}, error error)
|
unaryServerDegradeHandler func(ctx context.Context, req interface{}) (reply interface{}, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCircuitBreakerOptions() *circuitBreakerOptions {
|
func defaultCircuitBreakerOptions() *circuitBreakerOptions {
|
||||||
|
@ -66,7 +66,7 @@ func WithValidCode(code ...codes.Code) CircuitBreakerOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithUnaryServerDegradeHandler unary server degrade handler function
|
// WithUnaryServerDegradeHandler unary server degrade handler function
|
||||||
func WithUnaryServerDegradeHandler(handler func(ctx context.Context, req interface{}) (reply interface{}, error error)) CircuitBreakerOption {
|
func WithUnaryServerDegradeHandler(handler func(ctx context.Context, req interface{}) (reply interface{}, err error)) CircuitBreakerOption {
|
||||||
return func(o *circuitBreakerOptions) {
|
return func(o *circuitBreakerOptions) {
|
||||||
o.unaryServerDegradeHandler = handler
|
o.unaryServerDegradeHandler = handler
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@ var defaultMaxSize = 1000
|
||||||
const oidName = "_id"
|
const oidName = "_id"
|
||||||
|
|
||||||
// SetMaxSize change the default maximum number of pages per page
|
// SetMaxSize change the default maximum number of pages per page
|
||||||
func SetMaxSize(max int) {
|
func SetMaxSize(maxValue int) {
|
||||||
if max < 10 {
|
if maxValue < 10 {
|
||||||
max = 10
|
maxValue = 10
|
||||||
}
|
}
|
||||||
defaultMaxSize = max
|
defaultMaxSize = maxValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Page info
|
// Page info
|
||||||
|
|
|
@ -5,11 +5,11 @@ import "strings"
|
||||||
var defaultMaxSize = 1000
|
var defaultMaxSize = 1000
|
||||||
|
|
||||||
// SetMaxSize change the default maximum number of pages per page
|
// SetMaxSize change the default maximum number of pages per page
|
||||||
func SetMaxSize(max int) {
|
func SetMaxSize(maxValue int) {
|
||||||
if max < 10 {
|
if maxValue < 10 {
|
||||||
max = 10
|
maxValue = 10
|
||||||
}
|
}
|
||||||
defaultMaxSize = max
|
defaultMaxSize = maxValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Page info
|
// Page info
|
||||||
|
|
|
@ -45,8 +45,8 @@ var currentDriver string
|
||||||
|
|
||||||
// SetDriver sets the name of the current database driver, such as "postgres"
|
// SetDriver sets the name of the current database driver, such as "postgres"
|
||||||
// if you use postgres, you need to call SetDriver("postgres") after initializing gorm
|
// if you use postgres, you need to call SetDriver("postgres") after initializing gorm
|
||||||
func SetDriver(driver string) {
|
func SetDriver(driverName string) {
|
||||||
currentDriver = driver
|
currentDriver = driverName
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -63,19 +63,19 @@ func ParseUintList(val string) (map[int]bool, error) {
|
||||||
}
|
}
|
||||||
availableInts[v] = true
|
availableInts[v] = true
|
||||||
} else {
|
} else {
|
||||||
split := strings.SplitN(r, "-", 2)
|
ss := strings.SplitN(r, "-", 2)
|
||||||
min, err := strconv.Atoi(split[0])
|
minVal, err := strconv.Atoi(ss[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errInvalidFormat
|
return nil, errInvalidFormat
|
||||||
}
|
}
|
||||||
max, err := strconv.Atoi(split[1])
|
maxVal, err := strconv.Atoi(ss[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errInvalidFormat
|
return nil, errInvalidFormat
|
||||||
}
|
}
|
||||||
if max < min {
|
if maxVal < minVal {
|
||||||
return nil, errInvalidFormat
|
return nil, errInvalidFormat
|
||||||
}
|
}
|
||||||
for i := min; i <= max; i++ {
|
for i := minVal; i <= maxVal; i++ {
|
||||||
availableInts[i] = true
|
availableInts[i] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,14 +43,14 @@ func cpuproc() {
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
stat := &cpu.Stat{}
|
stat := &cpu.Stat{}
|
||||||
cpu.ReadStat(stat)
|
cpu.ReadStat(stat)
|
||||||
stat.Usage = min(stat.Usage, 1000)
|
stat.Usage = getMin(stat.Usage, 1000)
|
||||||
prevCPU := atomic.LoadInt64(&gCPU)
|
prevCPU := atomic.LoadInt64(&gCPU)
|
||||||
curCPU := int64(float64(prevCPU)*decay + float64(stat.Usage)*(1.0-decay))
|
curCPU := int64(float64(prevCPU)*decay + float64(stat.Usage)*(1.0-decay))
|
||||||
atomic.StoreInt64(&gCPU, curCPU)
|
atomic.StoreInt64(&gCPU, curCPU)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func min(l, r uint64) uint64 {
|
func getMin(l, r uint64) uint64 {
|
||||||
if l < r {
|
if l < r {
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,8 @@ func (p *WaitPrinter) LoopPrint(runningTip string) {
|
||||||
index++
|
index++
|
||||||
if index >= len(symbols) {
|
if index >= len(symbols) {
|
||||||
index = 0
|
index = 0
|
||||||
p.clearCurrentLine()
|
|
||||||
}
|
}
|
||||||
|
p.clearCurrentLine()
|
||||||
fmt.Printf("\r%s", symbols[index])
|
fmt.Printf("\r%s", symbols[index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,9 +70,6 @@ func (p *WaitPrinter) StopPrint(tip string) {
|
||||||
|
|
||||||
p.cancel()
|
p.cancel()
|
||||||
p.clearCurrentLine()
|
p.clearCurrentLine()
|
||||||
if tip == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Println(tip)
|
fmt.Println(tip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue