pub struct GoutClient { /* private fields */ }Expand description
隧道操作客户端。
使用服务端分配的普通 api-key(非 admin key)进行认证。
客户端实例持有 HTTP 连接池,建议复用。
§示例
use gout_api::client::GoutClient;
use gout_api::TunnelType;
let gout = GoutClient::new("server.example.com:8080", "sk-your-key");
let tunnel = gout.create_tunnel(TunnelType::Tcp, 4000).await.unwrap();
gout.delete_tunnel(tunnel.token).await.unwrap();Implementations§
Source§impl GoutClient
impl GoutClient
Sourcepub async fn create_tunnel(
&self,
tunnel_type: TunnelType,
local_port: u16,
) -> Result<TunnelResponse>
pub async fn create_tunnel( &self, tunnel_type: TunnelType, local_port: u16, ) -> Result<TunnelResponse>
创建一个新隧道。
返回 TunnelResponse,调用方据此建立数据通道连接。
数据通道的握手和 pipe 由 data_channel 模块提供。
§参数
tunnel_type— 隧道协议类型(TCP / UDP / HTTP)local_port— 本地服务端口号
Sourcepub async fn list_tunnels(&self) -> Result<Vec<TunnelListEntry>>
pub async fn list_tunnels(&self) -> Result<Vec<TunnelListEntry>>
列出所有活跃隧道。
返回当前服务端上状态为 “waiting” 或 “active” 的隧道列表。 已关闭或已过期的隧道不会出现在列表中。
Sourcepub async fn delete_tunnel(&self, token: u64) -> Result<()>
pub async fn delete_tunnel(&self, token: u64) -> Result<()>
删除指定 token 的隧道。
服务端会关闭对应的公网端口监听并清理所有相关资源。
Sourcepub fn server_addr(&self) -> &str
pub fn server_addr(&self) -> &str
获取服务端地址(不含 http:// 前缀)。
Auto Trait Implementations§
impl !RefUnwindSafe for GoutClient
impl !UnwindSafe for GoutClient
impl Freeze for GoutClient
impl Send for GoutClient
impl Sync for GoutClient
impl Unpin for GoutClient
impl UnsafeUnpin for GoutClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more