单二进制三角色 + Dock 适配器 + Swarm stack 达到可部署态;mgr1 实测订阅经 central-proxy bootstrap,探活 alive=41/52。 Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
929 B
Go
34 lines
929 B
Go
// 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"
|
||
}
|
||
}
|