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

- 移除hostinfo_ext.go中7个未使用函数 - 移除target.go中7个未使用函数 - 清理多余空行,提升代码简洁性 - 保持核心功能完整,仅删除确认未被调用的函数 - 消除所有死代码编译警告
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
// HostInfoHelper 提供HostInfo的辅助方法
|
|
// 使用函数而不是方法,保持向后兼容
|
|
|
|
|
|
// GetPort 获取端口号(转换为整数)
|
|
func GetPort(h *HostInfo) (int, error) {
|
|
if h.Ports == "" {
|
|
return 0, fmt.Errorf("端口未设置")
|
|
}
|
|
return strconv.Atoi(h.Ports)
|
|
}
|
|
|
|
|
|
// IsWebTarget 判断是否为Web目标
|
|
func IsWebTarget(h *HostInfo) bool {
|
|
return h.Url != ""
|
|
}
|
|
|
|
// HasPort 检查是否设置了端口
|
|
func HasPort(h *HostInfo) bool {
|
|
return h.Ports != ""
|
|
}
|
|
|
|
// ValidateHostInfo 验证HostInfo的有效性
|
|
func ValidateHostInfo(h *HostInfo) error {
|
|
if h.Host == "" && h.Url == "" {
|
|
return fmt.Errorf("主机地址或URL必须至少指定一个")
|
|
}
|
|
|
|
// 验证端口格式(如果指定了)
|
|
if h.Ports != "" {
|
|
if _, err := GetPort(h); err != nil {
|
|
return fmt.Errorf("端口格式无效: %v", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// HostInfoString 返回HostInfo的字符串表示
|
|
func HostInfoString(h *HostInfo) string {
|
|
if IsWebTarget(h) {
|
|
return h.Url
|
|
}
|
|
|
|
if HasPort(h) {
|
|
return fmt.Sprintf("%s:%s", h.Host, h.Ports)
|
|
}
|
|
|
|
return h.Host
|
|
} |