mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 11:20:41 +08:00
- 删除冗余的中间层(XXXInput、XXXParser类) - 新增 config_builder.go 统一配置构建 - parsers包从3000+行精简至~540行 - 保留核心函数:ParseIP、ParsePort、文件读取、凭据解析
102 lines
2.3 KiB
Go
102 lines
2.3 KiB
Go
package common
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/shadow1ng/fscan/common/logging"
|
|
)
|
|
|
|
/*
|
|
parse.go - 解析相关工具函数
|
|
|
|
重构后只保留:
|
|
- RemoveDuplicate - 字符串去重
|
|
- applyLogLevel - 日志级别应用
|
|
- 辅助函数
|
|
*/
|
|
|
|
// RemoveDuplicate 去重函数
|
|
func RemoveDuplicate(old []string) []string {
|
|
if len(old) <= 1 {
|
|
return old
|
|
}
|
|
|
|
temp := make(map[string]struct{}, len(old))
|
|
result := make([]string, 0, len(old))
|
|
|
|
for _, item := range old {
|
|
if _, exists := temp[item]; !exists {
|
|
temp[item] = struct{}{}
|
|
result = append(result, item)
|
|
}
|
|
}
|
|
|
|
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,
|
|
LogLevelError: logging.LevelError,
|
|
LogLevelBase: logging.LevelBase,
|
|
LogLevelInfo: logging.LevelInfo,
|
|
LogLevelSuccess: logging.LevelSuccess,
|
|
LogLevelDebug: logging.LevelDebug,
|
|
LogLevelInfoSuccess: logging.LevelInfoSuccess,
|
|
LogLevelBaseInfoSuccess: logging.LevelBaseInfoSuccess,
|
|
// 旧格式(大写,向后兼容)
|
|
"ALL": logging.LevelAll,
|
|
"ERROR": logging.LevelError,
|
|
"BASE": logging.LevelBase,
|
|
"INFO": logging.LevelInfo,
|
|
"SUCCESS": logging.LevelSuccess,
|
|
"DEBUG": logging.LevelDebug,
|
|
}
|
|
|
|
// applyLogLevel 应用LogLevel配置到日志系统
|
|
func applyLogLevel() {
|
|
fv := GetFlagVars()
|
|
logLevel := fv.LogLevel
|
|
if logLevel == "" {
|
|
return
|
|
}
|
|
|
|
level, ok := logLevelMap[logLevel]
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
if globalLogger != nil {
|
|
config := &logging.LoggerConfig{
|
|
Level: level,
|
|
EnableColor: !fv.NoColor,
|
|
SlowOutput: false,
|
|
ShowProgress: !fv.DisableProgress,
|
|
StartTime: GetGlobalState().GetStartTime(),
|
|
LevelColors: logging.GetDefaultLevelColors(),
|
|
}
|
|
|
|
newLogger := logging.NewLogger(config)
|
|
newLogger.SetCoordinatedOutput(LogWithProgress)
|
|
globalLogger = newLogger
|
|
}
|
|
}
|