onesvm-browser-server/server/internal/httpx/dial.go
chii eb972dfa93 feat: 落地 browser-server 控制面并打通 mgr1 海外订阅
单二进制三角色 + Dock 适配器 + Swarm stack 达到可部署态;mgr1 实测订阅经 central-proxy bootstrap,探活 alive=41/52。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 15:05:12 +08:00

34 lines
929 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// dial.go:网络拨号器(10s dial 超时)。
package httpx
import (
"context"
"net"
"time"
)
// netDialer 带超时的拨号器(httpx 内部封装,不外泄 net 依赖到调用方)。
type netDialer struct{ timeout time.Duration }
// DialContext 实现 net.Dialer 语义。
func (d *netDialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error) {
var nd net.Dialer
cctx, cancel := context.WithTimeout(ctx, d.timeout)
defer cancel()
return nd.DialContext(cctx, network, addr)
}
// 错误码映射(W2 模版层使用):httpx 错误类型 → contract 错误码字面量。
// BlockedError→blocked;DeniedError→denied;TimeoutError→timeout;其余→upstream。
func ErrorCode(err error) string {
switch err.(type) {
case *BlockedError:
return "blocked"
case *DeniedError:
return "denied"
case *TimeoutError:
return "timeout"
default:
return "upstream"
}
}