@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -108,13 +109,18 @@ func (s *ProxyService) probeGeo(ctx context.Context, id uint) {
|
||||
break
|
||||
}
|
||||
}
|
||||
var row model.Proxy
|
||||
if err := s.db.WithContext(ctx).First(&row, id).Error; err != nil {
|
||||
return
|
||||
}
|
||||
s.persistGeo(ctx, id, res)
|
||||
}
|
||||
|
||||
// persistGeo 条件更新地区字段:代理已被删除时零命中放弃——整行 Save 零命中会
|
||||
// 回退 Create 把删掉的代理复活;错误也不能静默吞掉。
|
||||
func (s *ProxyService) persistGeo(ctx context.Context, id uint, res geoResult) {
|
||||
now := time.Now()
|
||||
row.Country, row.City, row.GeoAt = res.Country, res.City, &now
|
||||
s.db.WithContext(ctx).Save(&row)
|
||||
tx := s.db.WithContext(ctx).Model(&model.Proxy{}).Where("id = ?", id).
|
||||
Updates(map[string]any{"country": res.Country, "city": res.City, "geo_at": &now})
|
||||
if tx.Error != nil {
|
||||
log.Printf("proxy geo persist %d: %v", id, tx.Error)
|
||||
}
|
||||
}
|
||||
|
||||
// Probe 同步重测代理出口地理并返回最新视图;供手动「重测」入口调用。
|
||||
|
||||
Reference in New Issue
Block a user