SNI_proxy/main.go

47 lines
972 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"github.com/SNI_Proxy/config"
"github.com/SNI_Proxy/proxy"
)
func main() {
// 解析命令行参数
configPath := flag.String("config", "config.yaml", "配置文件路径")
flag.Parse()
// 加载配置
cfg, err := config.LoadConfig(*configPath)
if err != nil {
log.Fatalf("加载配置失败: %v", err)
}
// 创建并启动代理服务器
server := proxy.NewServer(cfg)
if err := server.Start(); err != nil {
log.Fatalf("启动代理服务器失败: %v", err)
}
log.Printf("SNI代理服务器已启动监听地址: %s", cfg.Listen)
// 等待中断信号以优雅地关闭服务器
waitForInterrupt(server)
}
// 等待中断信号
func waitForInterrupt(server *proxy.Server) {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
<-sigChan
log.Println("正在关闭服务器...")
server.Stop()
log.Println("服务器已关闭")
}