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:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -98,3 +98,5 @@ check_ban.py
|
|||||||
.kiro/specs/codex-pool-frontend/design.md
|
.kiro/specs/codex-pool-frontend/design.md
|
||||||
.kiro/specs/codex-pool-frontend/requirements.md
|
.kiro/specs/codex-pool-frontend/requirements.md
|
||||||
.kiro/specs/codex-pool-frontend/tasks.md
|
.kiro/specs/codex-pool-frontend/tasks.md
|
||||||
|
backend/codex-pool.exe
|
||||||
|
backend/codex-pool.exe
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -122,7 +123,12 @@ func startServer(cfg *config.Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addr := fmt.Sprintf(":%d", cfg.Port)
|
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()
|
fmt.Println()
|
||||||
|
|
||||||
if err := http.ListenAndServe(addr, mux); err != nil {
|
if err := http.ListenAndServe(addr, mux); err != nil {
|
||||||
@@ -349,3 +355,28 @@ func handleRegisterTest(w http.ResponseWriter, r *http.Request) {
|
|||||||
"access_token": reg.AccessToken,
|
"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 ""
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user