Skip to content

Commit c5540c2

Browse files
committed
build: version 3.0.0
1 parent f12c206 commit c5540c2

File tree

6 files changed

+104
-85
lines changed

6 files changed

+104
-85
lines changed

internal/api/tunnel.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (h *TunnelHandler) HandleCreateTunnel(c *gin.Context) {
179179
Min json.RawMessage `json:"min"`
180180
Max json.RawMessage `json:"max"`
181181
Slot json.RawMessage `json:"slot"` // 新增:最大连接数限制
182-
Mode *string `json:"mode,omitempty"` // 新增:运行模式 (0, 1, 2)
182+
Mode *int `json:"mode,omitempty"` // 新增:运行模式 (0, 1, 2)
183183
Read *string `json:"read,omitempty"` // 新增:数据读取超时时间
184184
Rate *string `json:"rate,omitempty"` // 新增:带宽速率限制
185185
EnableSSEStore *bool `json:"enable_sse_store,omitempty"` // 新增:是否启用SSE存储
@@ -582,7 +582,7 @@ func (h *TunnelHandler) HandleUpdateTunnel(c *gin.Context) {
582582
Min json.RawMessage `json:"min"`
583583
Max json.RawMessage `json:"max"`
584584
Slot json.RawMessage `json:"slot"` // 新增:最大连接数限制
585-
Mode *string `json:"mode,omitempty"` // 新增:运行模式
585+
Mode *int `json:"mode,omitempty"` // 新增:运行模式
586586
Read *string `json:"read,omitempty"` // 新增:数据读取超时时间
587587
Rate *string `json:"rate,omitempty"` // 新增:带宽速率限制
588588
EnableSSEStore *bool `json:"enable_sse_store,omitempty"` // 新增:是否启用SSE存储
@@ -662,8 +662,7 @@ func (h *TunnelHandler) HandleUpdateTunnel(c *gin.Context) {
662662
// 处理Mode字段的类型转换
663663
var modePtr *tunnel.TunnelMode
664664
if rawCreate.Mode != nil {
665-
mode := tunnel.TunnelMode(*rawCreate.Mode)
666-
modePtr = &mode
665+
modePtr = (*tunnel.TunnelMode)(rawCreate.Mode)
667666
}
668667

669668
createReq := tunnel.CreateTunnelRequest{
@@ -1153,9 +1152,16 @@ func (h *TunnelHandler) HandleGetTunnelDetails(c *gin.Context) {
11531152
targetPort, _ := strconv.Atoi(tunnelRecord.TargetPort)
11541153

11551154
// 处理新字段的NULL值
1156-
mode := ""
1155+
var mode interface{}
11571156
if tunnelRecord.Mode.Valid {
1158-
mode = tunnelRecord.Mode.String
1157+
modeInt, err := strconv.Atoi(tunnelRecord.Mode.String)
1158+
if err != nil {
1159+
mode = nil
1160+
} else {
1161+
mode = modeInt
1162+
}
1163+
} else {
1164+
mode = nil
11591165
}
11601166
read := ""
11611167
if tunnelRecord.Read.Valid {
@@ -3006,7 +3012,7 @@ func (h *TunnelHandler) HandleUpdateTunnelV2(c *gin.Context) {
30063012
Min json.RawMessage `json:"min"`
30073013
Max json.RawMessage `json:"max"`
30083014
Slot json.RawMessage `json:"slot"` // 新增:最大连接数限制
3009-
Mode *string `json:"mode,omitempty"` // 新增:运行模式
3015+
Mode *int `json:"mode,omitempty"` // 新增:运行模式
30103016
Read *string `json:"read,omitempty"` // 新增:数据读取超时时间
30113017
Rate *string `json:"rate,omitempty"` // 新增:带宽速率限制
30123018
EnableSSEStore *bool `json:"enable_sse_store,omitempty"` // 新增:是否启用SSE存储
@@ -3155,8 +3161,7 @@ func (h *TunnelHandler) HandleUpdateTunnelV2(c *gin.Context) {
31553161
// 处理Mode字段的类型转换
31563162
var modePtr *tunnel.TunnelMode
31573163
if raw.Mode != nil {
3158-
mode := tunnel.TunnelMode(*raw.Mode)
3159-
modePtr = &mode
3164+
modePtr = (*tunnel.TunnelMode)(raw.Mode)
31603165
}
31613166

31623167
createReq := tunnel.CreateTunnelRequest{

internal/endpoint/service.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (s *Service) UpdateEndpoint(req UpdateEndpointRequest) (*Endpoint, error) {
250250
// 修改配置:更新名称、URL、API路径,可选的API密钥
251251
updates := make(map[string]interface{})
252252
needUpdateCache := false
253-
253+
254254
if req.Name != "" {
255255
// 检查新名称是否已存在
256256
var count int64
@@ -262,7 +262,7 @@ func (s *Service) UpdateEndpoint(req UpdateEndpointRequest) (*Endpoint, error) {
262262
}
263263
updates["name"] = req.Name
264264
}
265-
265+
266266
if req.URL != "" && req.URL != endpoint.URL {
267267
// 检查URL是否重复
268268
var count int64
@@ -279,17 +279,17 @@ func (s *Service) UpdateEndpoint(req UpdateEndpointRequest) (*Endpoint, error) {
279279
}
280280
needUpdateCache = true
281281
}
282-
282+
283283
if req.APIPath != "" && req.APIPath != endpoint.APIPath {
284284
updates["api_path"] = req.APIPath
285285
needUpdateCache = true
286286
}
287-
287+
288288
if req.APIKey != "" && req.APIKey != endpoint.APIKey {
289289
updates["api_key"] = req.APIKey
290290
needUpdateCache = true
291291
}
292-
292+
293293
updates["updated_at"] = time.Now()
294294

295295
if err := s.db.Model(&endpoint).Updates(updates).Error; err != nil {
@@ -311,7 +311,7 @@ func (s *Service) UpdateEndpoint(req UpdateEndpointRequest) (*Endpoint, error) {
311311
if req.APIKey == "" {
312312
return nil, errors.New("API密钥不能为空")
313313
}
314-
314+
315315
updates := map[string]interface{}{
316316
"api_key": req.APIKey,
317317
"updated_at": time.Now(),

internal/models/enums.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ const (
5151
)
5252

5353
// TLSMode TLS模式枚举
54-
type TunnelMode string
54+
type TunnelMode int
5555

5656
const (
57-
Mode0 TunnelMode = "0"
58-
Mode1 TunnelMode = "1"
59-
Mode2 TunnelMode = "2"
57+
Mode0 TunnelMode = 0
58+
Mode1 TunnelMode = 1
59+
Mode2 TunnelMode = 2
6060
)
6161

6262
// LogLevel 日志级别枚举

internal/sse/service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ func buildTunnel(payload SSEResp) *models.Tunnel {
284284
tunnel.Restart = payload.Instance.Restart
285285
tunnel.Name = *payload.Instance.Alias
286286
tunnel.Status = models.TunnelStatus(payload.Instance.Status)
287+
log.Infof("%v解析mode=%v", tunnel.InstanceID, tunnel.Mode)
288+
if tunnel.Mode == nil {
289+
log.Infof("%v url未显式模式,尝试使用mode字段", tunnel.InstanceID)
290+
tunnel.Mode = (*models.TunnelMode)(payload.Instance.Mode)
291+
}
287292
return tunnel
288293
}
289294

internal/websocket/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (s *Service) endpointMonitorWorker(ctx context.Context, endpointID int64) {
252252

253253
// instanceMonitorWorker instance监控worker,每2秒查询一次instance接口
254254
func (s *Service) instanceMonitorWorker(ctx context.Context, instanceID string) {
255-
ticker := time.NewTicker(2 * time.Second)
255+
ticker := time.NewTicker(4 * time.Second)
256256
defer ticker.Stop()
257257

258258
log.Infof("Instance %s 监控worker已启动,开始每2秒查询instance接口", instanceID)

0 commit comments

Comments
 (0)