mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00
refactor: 清理未使用的死代码函数
- 移除hostinfo_ext.go中7个未使用函数 - 移除target.go中7个未使用函数 - 清理多余空行,提升代码简洁性 - 保持核心功能完整,仅删除确认未被调用的函数 - 消除所有死代码编译警告
This commit is contained in:
parent
792a075172
commit
defe5b0733
@ -8,10 +8,6 @@ import (
|
|||||||
// HostInfoHelper 提供HostInfo的辅助方法
|
// HostInfoHelper 提供HostInfo的辅助方法
|
||||||
// 使用函数而不是方法,保持向后兼容
|
// 使用函数而不是方法,保持向后兼容
|
||||||
|
|
||||||
// GetHost 获取主机地址
|
|
||||||
func GetHost(h *HostInfo) string {
|
|
||||||
return h.Host
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPort 获取端口号(转换为整数)
|
// GetPort 获取端口号(转换为整数)
|
||||||
func GetPort(h *HostInfo) (int, error) {
|
func GetPort(h *HostInfo) (int, error) {
|
||||||
@ -21,10 +17,6 @@ func GetPort(h *HostInfo) (int, error) {
|
|||||||
return strconv.Atoi(h.Ports)
|
return strconv.Atoi(h.Ports)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetURL 获取URL地址
|
|
||||||
func GetURL(h *HostInfo) string {
|
|
||||||
return h.Url
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsWebTarget 判断是否为Web目标
|
// IsWebTarget 判断是否为Web目标
|
||||||
func IsWebTarget(h *HostInfo) bool {
|
func IsWebTarget(h *HostInfo) bool {
|
||||||
@ -36,28 +28,6 @@ func HasPort(h *HostInfo) bool {
|
|||||||
return h.Ports != ""
|
return h.Ports != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasHost 检查是否设置了主机
|
|
||||||
func HasHost(h *HostInfo) bool {
|
|
||||||
return h.Host != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloneHostInfo 克隆HostInfo(深拷贝)
|
|
||||||
func CloneHostInfo(h *HostInfo) HostInfo {
|
|
||||||
cloned := HostInfo{
|
|
||||||
Host: h.Host,
|
|
||||||
Ports: h.Ports,
|
|
||||||
Url: h.Url,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 深拷贝Infostr切片
|
|
||||||
if h.Infostr != nil {
|
|
||||||
cloned.Infostr = make([]string, len(h.Infostr))
|
|
||||||
copy(cloned.Infostr, h.Infostr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return cloned
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidateHostInfo 验证HostInfo的有效性
|
// ValidateHostInfo 验证HostInfo的有效性
|
||||||
func ValidateHostInfo(h *HostInfo) error {
|
func ValidateHostInfo(h *HostInfo) error {
|
||||||
if h.Host == "" && h.Url == "" {
|
if h.Host == "" && h.Url == "" {
|
||||||
@ -85,25 +55,4 @@ func HostInfoString(h *HostInfo) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return h.Host
|
return h.Host
|
||||||
}
|
|
||||||
|
|
||||||
// AddInfo 添加附加信息
|
|
||||||
func AddInfo(h *HostInfo, info string) {
|
|
||||||
if h.Infostr == nil {
|
|
||||||
h.Infostr = make([]string, 0)
|
|
||||||
}
|
|
||||||
h.Infostr = append(h.Infostr, info)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInfo 获取所有附加信息
|
|
||||||
func GetInfo(h *HostInfo) []string {
|
|
||||||
if h.Infostr == nil {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
return h.Infostr
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasInfo 检查是否有附加信息
|
|
||||||
func HasInfo(h *HostInfo) bool {
|
|
||||||
return len(h.Infostr) > 0
|
|
||||||
}
|
}
|
@ -20,14 +20,6 @@ func NewTargetInfo(hostInfo HostInfo) *TargetInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTargetInfoFromPtr 从HostInfo指针创建目标信息
|
|
||||||
func NewTargetInfoFromPtr(hostInfo *HostInfo) *TargetInfo {
|
|
||||||
return &TargetInfo{
|
|
||||||
HostInfo: hostInfo,
|
|
||||||
context: context.Background(),
|
|
||||||
metadata: make(map[string]interface{}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithContext 设置上下文
|
// WithContext 设置上下文
|
||||||
func (t *TargetInfo) WithContext(ctx context.Context) *TargetInfo {
|
func (t *TargetInfo) WithContext(ctx context.Context) *TargetInfo {
|
||||||
@ -35,13 +27,6 @@ func (t *TargetInfo) WithContext(ctx context.Context) *TargetInfo {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetContext 获取上下文
|
|
||||||
func (t *TargetInfo) GetContext() context.Context {
|
|
||||||
if t.context == nil {
|
|
||||||
t.context = context.Background()
|
|
||||||
}
|
|
||||||
return t.context
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMetadata 设置元数据
|
// SetMetadata 设置元数据
|
||||||
func (t *TargetInfo) SetMetadata(key string, value interface{}) *TargetInfo {
|
func (t *TargetInfo) SetMetadata(key string, value interface{}) *TargetInfo {
|
||||||
@ -61,56 +46,15 @@ func (t *TargetInfo) GetMetadata(key string) (interface{}, bool) {
|
|||||||
return value, exists
|
return value, exists
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllMetadata 获取所有元数据
|
|
||||||
func (t *TargetInfo) GetAllMetadata() map[string]interface{} {
|
|
||||||
if t.metadata == nil {
|
|
||||||
return make(map[string]interface{})
|
|
||||||
}
|
|
||||||
// 返回副本,防止外部修改
|
|
||||||
result := make(map[string]interface{})
|
|
||||||
for k, v := range t.metadata {
|
|
||||||
result[k] = v
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clone 克隆目标信息
|
|
||||||
func (t *TargetInfo) Clone() *TargetInfo {
|
|
||||||
clonedHost := CloneHostInfo(t.HostInfo)
|
|
||||||
cloned := &TargetInfo{
|
|
||||||
HostInfo: &clonedHost,
|
|
||||||
context: t.context,
|
|
||||||
metadata: make(map[string]interface{}),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 复制元数据
|
|
||||||
for k, v := range t.metadata {
|
|
||||||
cloned.metadata[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
return cloned
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetHostInfo 获取原始HostInfo(向后兼容)
|
|
||||||
func (t *TargetInfo) GetHostInfo() HostInfo {
|
|
||||||
return *t.HostInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate 验证目标信息
|
|
||||||
func (t *TargetInfo) Validate() error {
|
|
||||||
return ValidateHostInfo(t.HostInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
// String 返回字符串表示
|
// String 返回字符串表示
|
||||||
func (t *TargetInfo) String() string {
|
func (t *TargetInfo) String() string {
|
||||||
return HostInfoString(t.HostInfo)
|
return HostInfoString(t.HostInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid 检查目标是否有效
|
|
||||||
func (t *TargetInfo) IsValid() bool {
|
|
||||||
return t.Validate() == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasMetadata 检查是否有指定的元数据
|
// HasMetadata 检查是否有指定的元数据
|
||||||
func (t *TargetInfo) HasMetadata(key string) bool {
|
func (t *TargetInfo) HasMetadata(key string) bool {
|
||||||
_, exists := t.GetMetadata(key)
|
_, exists := t.GetMetadata(key)
|
||||||
|
Loading…
Reference in New Issue
Block a user