netaddr

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

internal/pkg/netaddr/master_target.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentRelayTarget added in v0.0.13

func AgentRelayTarget(raw string) (string, error)

AgentRelayTarget validates and canonicalizes the dedicated relay websocket URI. Path and query are intentionally preserved because deployments may route the tunnel through a non-default ingress path or signed query parameters.

func AgentRelayURIFromMasterURL added in v0.0.13

func AgentRelayURIFromMasterURL(masterURL string) (string, bool)

AgentRelayURIFromMasterURL derives the dedicated relay endpoint beside the control endpoint while preserving deployment-specific path prefixes and query.

func Listen

func Listen(addr string) (net.Listener, error)

Listen 按 Parse 结果监听。文件型 unix 在监听前清理陈旧 socket 文件 (仅当残留文件确实是一个 socket 时才删,避免误删普通文件)。 抽象型 unix(前导 @)与 tcp 直接监听。

func MasterHTTPTarget added in v0.0.13

func MasterHTTPTarget(masterURL, path string) (*http.Client, string, error)

MasterHTTPTarget 把 agent 配置的 master_url("http://host:port" | "ws://..." | "unix:/path") 解析成可用的 HTTP client + 完整目标 URL。enrollment 与 usage 上传共用。

func Parse

func Parse(addr string) (network, address string)

Parse 把配置字符串解析为 net 包用的 (network, address)。 "unix:/x" → ("unix","/x");"unix:@x" → ("unix","@x");其余 → ("tcp", addr)。

func SelfClient

func SelfClient(addr string) (*http.Client, string)

SelfClient 返回回拨「自己 listen 地址」用的 http.Client 与 base URL。

unix → client 的 DialContext 固定拨该 socket,base = "http://unix"
tcp  → 普通 client,base = "http://127.0.0.1:<port>"

func UnixHTTPClient

func UnixHTTPClient(addr string) *http.Client

UnixHTTPClient returns an http.Client whose every request is routed to the unix socket named by a "unix:" address (e.g. "unix:/run/gw.sock" or "unix:@name"). Pair it with base URL "http://unix" — the host is ignored.

func WSDial

func WSDial(ctx context.Context, masterURL string, logger *zap.Logger, headers ...http.Header) (*ws.Client, error)

WSDial 拨 master 的 ws RPC 端点 /ws/agent。

masterURL 以 unix: 开头 → 占位 ws://unix/ws/agent + NetDialContext 拨该 socket
http(s)/ws(s)          → 转成 ws(s):// 并补 /ws/agent 后用默认 dialer

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL