mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-02-09 02:09:17 +08:00
refactor(common): 删除死代码,优化代码风格
- 删除未使用的 joinStrings/joinInts 函数 - 删除未使用的 memStats 字段和 getMemoryInfo 方法 - 简化 parsePasswords 中的循环为 append(...) 形式
This commit is contained in:
@@ -121,9 +121,7 @@ func parsePasswords(fv *FlagVars) []string {
|
||||
|
||||
// 命令行密码
|
||||
if fv.Password != "" {
|
||||
for _, p := range strings.Split(fv.Password, ",") {
|
||||
passwords = append(passwords, p)
|
||||
}
|
||||
passwords = append(passwords, strings.Split(fv.Password, ",")...)
|
||||
}
|
||||
|
||||
// 从文件读取
|
||||
@@ -135,9 +133,7 @@ func parsePasswords(fv *FlagVars) []string {
|
||||
|
||||
// 额外密码
|
||||
if fv.AddPasswords != "" {
|
||||
for _, p := range strings.Split(fv.AddPasswords, ",") {
|
||||
passwords = append(passwords, p)
|
||||
}
|
||||
passwords = append(passwords, strings.Split(fv.AddPasswords, ",")...)
|
||||
}
|
||||
|
||||
return removeDuplicate(passwords)
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/shadow1ng/fscan/common/logging"
|
||||
)
|
||||
|
||||
@@ -35,23 +32,6 @@ func RemoveDuplicate(old []string) []string {
|
||||
return result
|
||||
}
|
||||
|
||||
// joinStrings 连接字符串切片
|
||||
func joinStrings(slice []string, sep string) string {
|
||||
return strings.Join(slice, sep)
|
||||
}
|
||||
|
||||
// joinInts 连接整数切片
|
||||
func joinInts(slice []int, sep string) string {
|
||||
if len(slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
strs := make([]string, len(slice))
|
||||
for i, v := range slice {
|
||||
strs[i] = strconv.Itoa(v)
|
||||
}
|
||||
return strings.Join(strs, sep)
|
||||
}
|
||||
|
||||
// logLevelMap 日志级别字符串到级别的映射
|
||||
var logLevelMap = map[string]logging.LogLevel{
|
||||
LogLevelAll: logging.LevelAll,
|
||||
|
||||
@@ -3,7 +3,6 @@ package common
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -47,10 +46,6 @@ type ProgressManager struct {
|
||||
activityTicker *time.Ticker
|
||||
stopActivityChan chan struct{}
|
||||
|
||||
// 内存监控相关
|
||||
lastMemUpdate time.Time
|
||||
memStats runtime.MemStats
|
||||
|
||||
// 进度条更新控制(减少 Windows 终端的重复输出)
|
||||
lastRenderedPercent int
|
||||
}
|
||||
@@ -124,8 +119,7 @@ func (pm *ProgressManager) InitProgress(total int64, description string) {
|
||||
pm.enabled = true
|
||||
pm.lastActivity = time.Now()
|
||||
pm.spinnerIndex = 0
|
||||
pm.lastMemUpdate = time.Now().Add(-2 * time.Second) // 强制首次更新内存
|
||||
pm.lastRenderedPercent = -1 // 强制首次渲染
|
||||
pm.lastRenderedPercent = -1 // 强制首次渲染
|
||||
|
||||
// 为进度条保留空间
|
||||
pm.setupProgressSpace()
|
||||
@@ -609,36 +603,6 @@ func (pm *ProgressManager) getActivityIndicator() string {
|
||||
return spinnerChars[pm.spinnerIndex]
|
||||
}
|
||||
|
||||
// getMemoryInfo 获取内存使用信息
|
||||
func (pm *ProgressManager) getMemoryInfo() string {
|
||||
// 限制内存统计更新频率以提高性能(每秒最多一次)
|
||||
now := time.Now()
|
||||
if now.Sub(pm.lastMemUpdate) >= time.Second {
|
||||
runtime.ReadMemStats(&pm.memStats)
|
||||
pm.lastMemUpdate = now
|
||||
}
|
||||
|
||||
// 获取当前使用的内存(以MB为单位)
|
||||
memUsedMB := float64(pm.memStats.Alloc) / 1024 / 1024
|
||||
|
||||
// 根据内存使用量选择颜色
|
||||
var colorCode string
|
||||
if GetFlagVars().NoColor {
|
||||
return fmt.Sprintf("内存:%.1fMB", memUsedMB)
|
||||
}
|
||||
|
||||
// 根据内存使用量设置颜色
|
||||
if memUsedMB < 50 {
|
||||
colorCode = AnsiGreen // 绿色 - 内存使用较低
|
||||
} else if memUsedMB < 100 {
|
||||
colorCode = AnsiYellow // 黄色 - 内存使用中等
|
||||
} else {
|
||||
colorCode = AnsiRed // 红色 - 内存使用较高
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s内存:%.1fMB%s", colorCode, memUsedMB, AnsiReset)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// 并发监控器 (从 concurrency_monitor.go 合并)
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user