From 15887398e551e1784bf2fc06e007616068e9555f Mon Sep 17 00:00:00 2001 From: kyx236 Date: Fri, 30 Jan 2026 07:59:29 +0800 Subject: [PATCH] feat: Implement initial Go backend HTTP API server for Codex Pool, handling configuration, logging, S2A, mail, and team management, and ignore its executable. --- .gitignore | 2 ++ backend/cmd/main.go | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1c9dd4d..5f4e6d5 100644 --- a/.gitignore +++ b/.gitignore @@ -98,3 +98,5 @@ check_ban.py .kiro/specs/codex-pool-frontend/design.md .kiro/specs/codex-pool-frontend/requirements.md .kiro/specs/codex-pool-frontend/tasks.md +backend/codex-pool.exe +backend/codex-pool.exe diff --git a/backend/cmd/main.go b/backend/cmd/main.go index e45dc01..f41cc7e 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "net" "net/http" "os" "path/filepath" @@ -122,7 +123,12 @@ func startServer(cfg *config.Config) { } addr := fmt.Sprintf(":%d", cfg.Port) - fmt.Printf("[服务] 启动于 http://localhost%s\n", addr) + // 显示访问地址 + fmt.Println("[服务] 启动于:") + fmt.Printf(" - 本地: http://localhost:%d\n", cfg.Port) + if ip := getOutboundIP(); ip != "" { + fmt.Printf(" - 外部: http://%s:%d\n", ip, cfg.Port) + } fmt.Println() if err := http.ListenAndServe(addr, mux); err != nil { @@ -349,3 +355,28 @@ func handleRegisterTest(w http.ResponseWriter, r *http.Request) { "access_token": reg.AccessToken, }) } + +// getOutboundIP 获取本机出口 IP +func getOutboundIP() string { + // 方法1: 通过连接获取 + conn, err := net.Dial("udp", "8.8.8.8:80") + if err == nil { + defer conn.Close() + localAddr := conn.LocalAddr().(*net.UDPAddr) + return localAddr.IP.String() + } + + // 方法2: 遍历网卡 + addrs, err := net.InterfaceAddrs() + if err != nil { + return "" + } + for _, addr := range addrs { + if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { + if ipnet.IP.To4() != nil { + return ipnet.IP.String() + } + } + } + return "" +}