example

command
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

README

core/tunnel 示例集

每个子目录是一个独立可运行的 demo,单进程内跑通完整链路,方便拷贝改造。

目录 主题 演示的 API
example/main.go 基础:gateway / agent / backend 多模式 tunnelgateway.New / tunnelagent.New
quickstart/ 最简上手(推荐先看) tunnelagent.Standalone / tunnel.GetService / tunnel.ServiceURL
auth/ 代理鉴权(401 vs 200) tunnel.ConfigureGatewayAuth / GetService(token)
grpc/ gRPC over tunnel tunnel.GRPCContextDialer / GRPCDialOptions
tls/ TLS 加密隧道 GatewayConfig.TLS / AgentConfig.TLS(含 MinVersion

运行

go run ./core/tunnel/example/quickstart
go run ./core/tunnel/example/auth
go run ./core/tunnel/example/grpc
go run ./core/tunnel/example/tls

# 基础多模式示例(默认单进程跑全部)
go run ./core/tunnel/example            # = main.go, mode=all
go run ./core/tunnel/example -mode=gateway
go run ./core/tunnel/example -transport=quic

各 demo 使用独立端口段,互不冲突,可同时运行:

demo tunnel http/grpc backend
quickstart 17100 18100 18101
auth 17200 18200 18201
grpc 17300 19300 (grpc) 19301
tls 17400 18400 18401

相关文档

Documentation

Overview

Package main provides a simple example of using the tunnel package.

This example demonstrates: - Starting a Gateway server - Connecting an Agent to the Gateway - Registering services and proxying HTTP requests

Usage:

# Run all components together (gateway + agent + backend)
go run ./core/tunnel/example/main.go

# Run with different transport protocols
go run ./core/tunnel/example/main.go -transport=quic
go run ./core/tunnel/example/main.go -transport=kcp

# Run components separately (in different terminals)
go run ./core/tunnel/example/main.go -mode=backend
go run ./core/tunnel/example/main.go -mode=gateway
go run ./core/tunnel/example/main.go -mode=agent

# Verify request routing
curl http://127.0.0.1:18080/demo-svc/hello

Directories

Path Synopsis
Demo: 代理鉴权 —— 配置 TUNNEL_AUTH_TOKEN 后,HTTP 代理要求客户端携带 token。
Demo: 代理鉴权 —— 配置 TUNNEL_AUTH_TOKEN 后,HTTP 代理要求客户端携带 token。
Demo: gRPC over tunnel —— 经网关 gRPC 代理调用后端 gRPC 服务。
Demo: gRPC over tunnel —— 经网关 gRPC 代理调用后端 gRPC 服务。
Demo: 最简上手 —— Standalone Agent + HTTP 代理(单进程跑通)。
Demo: 最简上手 —— Standalone Agent + HTTP 代理(单进程跑通)。
Demo: TLS 传输 —— Agent ↔ Gateway 之间启用 TLS(yamux over TLS)。
Demo: TLS 传输 —— Agent ↔ Gateway 之间启用 TLS(yamux over TLS)。

Jump to

Keyboard shortcuts

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