feat: Implement initial Go backend HTTP API server for Codex Pool, handling configuration, logging, S2A, mail, and team management, and ignore its executable.

This commit is contained in:
2026-01-30 07:59:29 +08:00
parent 63e3e128f0
commit 15887398e5
2 changed files with 34 additions and 1 deletions

View File

@@ -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 ""
}