|
1 | 1 | package tunnel |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + log "NodePassDash/internal/log" |
4 | 5 | "database/sql" |
5 | 6 | "errors" |
6 | 7 | "fmt" |
7 | | - "log/slog" |
8 | 8 | "strconv" |
9 | 9 | "strings" |
10 | 10 | "time" |
@@ -154,7 +154,7 @@ func NewService(db *sql.DB) *Service { |
154 | 154 |
|
155 | 155 | // GetTunnels 获取所有隧道列表 |
156 | 156 | func (s *Service) GetTunnels() ([]TunnelWithStats, error) { |
157 | | - slog.Debug("GetTunnels called") |
| 157 | + log.Debugf("[Req] 获取所有隧道列表") |
158 | 158 | query := ` |
159 | 159 | SELECT |
160 | 160 | t.id, t.instanceId, t.name, t.endpointId, t.mode, |
@@ -259,7 +259,7 @@ func (s *Service) GetTunnels() ([]TunnelWithStats, error) { |
259 | 259 |
|
260 | 260 | // CreateTunnel 创建新隧道 |
261 | 261 | func (s *Service) CreateTunnel(req CreateTunnelRequest) (*Tunnel, error) { |
262 | | - slog.Info("CreateTunnel", "name", req.Name, "endpointId", req.EndpointID, "mode", req.Mode) |
| 262 | + log.Infof("[Req] 创建隧道: %v", req.Name) |
263 | 263 | // 检查端点是否存在 |
264 | 264 | var endpointURL, endpointAPIPath, endpointAPIKey string |
265 | 265 | err := s.db.QueryRow( |
@@ -448,7 +448,7 @@ func (s *Service) CreateTunnel(req CreateTunnelRequest) (*Tunnel, error) { |
448 | 448 |
|
449 | 449 | // DeleteTunnel 删除隧道 |
450 | 450 | func (s *Service) DeleteTunnel(instanceID string) error { |
451 | | - slog.Info("DeleteTunnel", "instanceId", instanceID) |
| 451 | + log.Infof("[Req] 删除隧道: %v", instanceID) |
452 | 452 | // 获取隧道信息 |
453 | 453 | var tunnel struct { |
454 | 454 | ID int64 |
@@ -537,7 +537,7 @@ func (s *Service) UpdateTunnelStatus(instanceID string, status TunnelStatus) err |
537 | 537 |
|
538 | 538 | // ControlTunnel 控制隧道状态(启动/停止/重启) |
539 | 539 | func (s *Service) ControlTunnel(req TunnelActionRequest) error { |
540 | | - slog.Info("ControlTunnel", "instanceId", req.InstanceID, "action", req.Action) |
| 540 | + log.Infof("[Req] 控制隧道状态: %v => %v", req.InstanceID, req.Action) |
541 | 541 | // 获取隧道和端点信息 |
542 | 542 | var tunnel struct { |
543 | 543 | ID int64 |
@@ -650,7 +650,7 @@ func formatTrafficBytes(bytes int64) string { |
650 | 650 |
|
651 | 651 | // UpdateTunnel 更新隧道配置 |
652 | 652 | func (s *Service) UpdateTunnel(req UpdateTunnelRequest) error { |
653 | | - slog.Info("UpdateTunnel", "id", req.ID) |
| 653 | + log.Infof("[Req] 更新隧道: %v", req.ID) |
654 | 654 | // 检查隧道是否存在 |
655 | 655 | var exists bool |
656 | 656 | err := s.db.QueryRow(`SELECT EXISTS(SELECT 1 FROM "Tunnel" WHERE id = ?)`, req.ID).Scan(&exists) |
@@ -842,7 +842,7 @@ func (s *Service) GetInstanceIDByTunnelID(id int64) (string, error) { |
842 | 842 | // 该方法不会主动删除本地记录,而是假设有其它进程 (如 SSE 监听) 负责删除 |
843 | 843 | // timeout 为等待的最长时长 |
844 | 844 | func (s *Service) DeleteTunnelAndWait(instanceID string, timeout time.Duration) error { |
845 | | - slog.Info("DeleteTunnelAndWait", "instanceId", instanceID, "timeout", timeout) |
| 845 | + log.Infof("[Req] 删除隧道: %v", instanceID) |
846 | 846 | // 获取隧道及端点信息(与 DeleteTunnel 中相同,但不删除本地记录) |
847 | 847 | var tunnel struct { |
848 | 848 | ID int64 |
@@ -889,7 +889,7 @@ func (s *Service) DeleteTunnelAndWait(instanceID string, timeout time.Duration) |
889 | 889 | } |
890 | 890 |
|
891 | 891 | // 超时仍未删除,执行本地强制删除并刷新计数 |
892 | | - slog.Warn("等待删除超时,执行本地删除", "instanceId", instanceID) |
| 892 | + log.Warnf("[Req] 等待删除超时,执行本地删除: %v", instanceID) |
893 | 893 |
|
894 | 894 | // 删除隧道记录 |
895 | 895 | result, err := s.db.Exec(`DELETE FROM "Tunnel" WHERE id = ?`, tunnel.ID) |
@@ -922,7 +922,7 @@ func (s *Service) DeleteTunnelAndWait(instanceID string, timeout time.Duration) |
922 | 922 |
|
923 | 923 | // RenameTunnel 仅修改隧道名称,不调用远端 API |
924 | 924 | func (s *Service) RenameTunnel(id int64, newName string) error { |
925 | | - slog.Info("RenameTunnel", "id", id, "newName", newName) |
| 925 | + log.Infof("[Req] 重命名隧道: %v", newName) |
926 | 926 |
|
927 | 927 | // 检查名称重复 |
928 | 928 | var exists bool |
|
0 commit comments