mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00

- 新增constants.go文件统一管理各包常量定义 - 提取logging、output、parsers、proxy包中的硬编码值 - 将30+个魔法数字替换为语义化常量 - 统一错误代码和消息格式 - 清理死代码和未使用变量 - 优化代码可维护性和可读性 - 保持完全向后兼容性 涉及包: - common/logging: 日志级别和格式常量 - common/output: 输出配置和格式常量 - common/parsers: 解析器配置和验证常量 - common/proxy: 代理协议和错误常量
148 lines
5.2 KiB
Go
148 lines
5.2 KiB
Go
package output
|
||
|
||
import (
|
||
"os"
|
||
"time"
|
||
)
|
||
|
||
/*
|
||
constants.go - 输出系统常量定义
|
||
|
||
统一管理common/output包中的所有常量,便于查看和编辑。
|
||
*/
|
||
|
||
// =============================================================================
|
||
// 输出格式常量 (从Types.go迁移)
|
||
// =============================================================================
|
||
|
||
// OutputFormat 输出格式类型
|
||
type OutputFormat string
|
||
|
||
const (
|
||
FormatTXT OutputFormat = "txt" // 文本格式
|
||
FormatJSON OutputFormat = "json" // JSON格式
|
||
FormatCSV OutputFormat = "csv" // CSV格式
|
||
)
|
||
|
||
// =============================================================================
|
||
// 结果类型常量 (从Types.go迁移)
|
||
// =============================================================================
|
||
|
||
// ResultType 定义结果类型
|
||
type ResultType string
|
||
|
||
const (
|
||
TypeHost ResultType = "HOST" // 主机存活
|
||
TypePort ResultType = "PORT" // 端口开放
|
||
TypeService ResultType = "SERVICE" // 服务识别
|
||
TypeVuln ResultType = "VULN" // 漏洞发现
|
||
)
|
||
|
||
// =============================================================================
|
||
// 默认配置常量
|
||
// =============================================================================
|
||
|
||
const (
|
||
// 默认缓冲区配置
|
||
DefaultBufferSize = 100 // 默认缓冲区大小
|
||
DefaultEnableBuffer = true // 默认启用缓冲
|
||
DefaultAutoFlush = true // 默认启用自动刷新
|
||
DefaultFlushInterval = 5 * time.Second // 默认刷新间隔
|
||
|
||
// 文件权限常量
|
||
DefaultFilePermissions = 0644 // 默认文件权限
|
||
DefaultDirPermissions = 0755 // 默认目录权限
|
||
|
||
// 文件操作标志
|
||
DefaultFileFlags = os.O_CREATE | os.O_WRONLY | os.O_APPEND // 默认文件打开标志
|
||
)
|
||
|
||
// =============================================================================
|
||
// CSV格式常量 (从Writers.go迁移)
|
||
// =============================================================================
|
||
|
||
var (
|
||
// CSV头部字段
|
||
CSVHeaders = []string{"Time", "Type", "Target", "Status", "Details"}
|
||
)
|
||
|
||
// =============================================================================
|
||
// 时间格式常量 (从Writers.go迁移)
|
||
// =============================================================================
|
||
|
||
const (
|
||
// 时间格式
|
||
DefaultTimeFormat = "2006-01-02 15:04:05" // 默认时间格式
|
||
ISO8601TimeFormat = "2006-01-02T15:04:05Z07:00" // ISO8601时间格式
|
||
ISO8601MilliFormat = "2006-01-02T15:04:05.000Z07:00" // ISO8601毫秒格式
|
||
)
|
||
|
||
// GetSupportedTimeFormats 获取支持的时间格式列表
|
||
func GetSupportedTimeFormats() []string {
|
||
return []string{
|
||
DefaultTimeFormat,
|
||
ISO8601TimeFormat,
|
||
ISO8601MilliFormat,
|
||
}
|
||
}
|
||
|
||
// =============================================================================
|
||
// JSON常量
|
||
// =============================================================================
|
||
|
||
const (
|
||
// JSON格式化
|
||
JSONIndentPrefix = "" // JSON缩进前缀
|
||
JSONIndentString = " " // JSON缩进字符串
|
||
|
||
// 空JSON对象
|
||
EmptyJSONObject = "{}"
|
||
)
|
||
|
||
// =============================================================================
|
||
// 文本格式常量 (从Writers.go迁移)
|
||
// =============================================================================
|
||
|
||
const (
|
||
// 文本输出格式
|
||
TxtTimeFormat = "2006-01-02 15:04:05" // 文本时间格式
|
||
TxtOutputTemplate = "[%s] [%s] %s - %s" // 文本输出模板
|
||
TxtDetailsFormat = " (%s)" // 详细信息格式
|
||
TxtNewline = "\n" // 换行符
|
||
TxtDetailsSeparator = ", " // 详细信息分隔符
|
||
TxtKeyValueFormat = "%s=%v" // 键值对格式
|
||
)
|
||
|
||
// =============================================================================
|
||
// 错误消息常量
|
||
// =============================================================================
|
||
|
||
const (
|
||
ErrConfigNil = "配置不能为空"
|
||
ErrUnsupportedFormat = "不支持的输出格式: %s"
|
||
ErrWriterInitFailed = "初始化写入器失败: %v"
|
||
ErrWriterClosed = "写入器已关闭"
|
||
ErrManagerNotInit = "输出管理器未初始化"
|
||
ErrManagerClosed = "输出管理器已关闭"
|
||
ErrWriteFailed = "写入结果失败: %v"
|
||
ErrFlushFailed = "刷新写入器失败: %v"
|
||
ErrCreateFileFailed = "创建%s文件失败: %v"
|
||
ErrWriteHeaderFailed = "写入CSV头部失败: %v"
|
||
ErrOpenFileFailed = "打开CSV文件失败: %v"
|
||
ErrReadFileFailed = "读取CSV文件失败: %v"
|
||
ErrParseTimeFailed = "无法解析时间: %s"
|
||
)
|
||
|
||
// =============================================================================
|
||
// CSV相关常量
|
||
// =============================================================================
|
||
|
||
const (
|
||
CSVMinColumns = 5 // CSV最小列数
|
||
CSVHeaderRowIndex = 0 // CSV头部行索引
|
||
CSVTimeColumnIndex = 0 // 时间列索引
|
||
CSVTypeColumnIndex = 1 // 类型列索引
|
||
CSVTargetColumnIndex = 2 // 目标列索引
|
||
CSVStatusColumnIndex = 3 // 状态列索引
|
||
CSVDetailsColumnIndex = 4 // 详细信息列索引
|
||
) |