feat: 修改编译参数

feat: 移除了多余的pprof包导入
fix: 服务器关闭时不再等待5s
This commit is contained in:
Pan Qiancheng 2025-10-17 11:50:14 +08:00
parent 71326a0e19
commit 8187d3a66d
3 changed files with 2 additions and 10 deletions

View File

@ -15,13 +15,13 @@ build: build-server build-client
# 编译服务器
build-server:
@echo "编译服务器..."
go build -o ../bin/server ./server
go build -ldflags "-s -w" -o ../bin/server ./server
@echo "服务器编译完成: bin/server"
# 编译客户端
build-client:
@echo "编译客户端..."
go build -o ../bin/client ./client
go build -ldflags "-s -w" -o ../bin/client ./client
@echo "客户端编译完成: bin/client"
# 运行服务器

View File

@ -3,7 +3,6 @@ package main
import (
"flag"
"log"
_ "net/http/pprof" // 导入pprof用于性能分析
"os"
"os/signal"
"port-forward/client/tunnel"

View File

@ -1,10 +1,8 @@
package main
import (
"context"
"flag"
"log"
_ "net/http/pprof" // 导入pprof用于性能分析
"os"
"os/signal"
"port-forward/server/api"
@ -14,7 +12,6 @@ import (
"port-forward/server/tunnel"
"port-forward/server/utils"
"syscall"
"time"
)
func main() {
@ -146,13 +143,9 @@ func main() {
log.Println("\n接收到关闭信号正在优雅关闭...")
// 创建关闭上下文
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// 停止所有转发器
log.Println("停止所有端口转发...")
fwdManager.StopAll()
log.Println("服务器已关闭")
<-ctx.Done()
}