Compare commits
No commits in common. "master" and "feature/gd10086" have entirely different histories.
master
...
feature/gd
|
|
@ -4,11 +4,9 @@ import (
|
||||||
errors "ai_scheduler/internal/data/error"
|
errors "ai_scheduler/internal/data/error"
|
||||||
"ai_scheduler/internal/gateway"
|
"ai_scheduler/internal/gateway"
|
||||||
"ai_scheduler/internal/services"
|
"ai_scheduler/internal/services"
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -18,11 +16,6 @@ import (
|
||||||
"github.com/gofiber/websocket/v2"
|
"github.com/gofiber/websocket/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
scbankQualificationProxyURL = "http://101.204.7.15:11857"
|
|
||||||
scbankQualificationProxyTimeout = 30 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
type RouterServer struct {
|
type RouterServer struct {
|
||||||
app *fiber.App
|
app *fiber.App
|
||||||
service *services.ChatService
|
service *services.ChatService
|
||||||
|
|
@ -113,7 +106,6 @@ func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionServi
|
||||||
|
|
||||||
// 转发Python服务
|
// 转发Python服务
|
||||||
r.All("/proxy/fingerprint", forwardToPythonService)
|
r.All("/proxy/fingerprint", forwardToPythonService)
|
||||||
r.All("/proxy/scbank/qualification", forwardScbankQualification)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func forwardToPythonService(c *fiber.Ctx) error {
|
func forwardToPythonService(c *fiber.Ctx) error {
|
||||||
|
|
@ -158,68 +150,6 @@ func forwardToPythonService(c *fiber.Ctx) error {
|
||||||
return c.Send(body)
|
return c.Send(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func forwardScbankQualification(c *fiber.Ctx) error {
|
|
||||||
requestBody := c.Body()
|
|
||||||
requestQuery := c.Context().QueryArgs().String()
|
|
||||||
|
|
||||||
// 调用外部权益接口前记录目标地址与关键请求信息,便于排查白名单和超时问题。
|
|
||||||
startAt := time.Now()
|
|
||||||
log.Printf("开始转发权益校验请求 | method=%s | path=%s | target=%s | query=%s | headers=%s | body=%s", c.Method(), c.Path(), scbankQualificationProxyURL, requestQuery, formatHeaders(c.GetReqHeaders()), string(requestBody))
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(c.Context(), c.Method(), scbankQualificationProxyURL, bytes.NewReader(requestBody))
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("创建权益中转请求失败 | target=%s | err=%v", scbankQualificationProxyURL, err)
|
|
||||||
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Request().Header.VisitAll(func(key, value []byte) {
|
|
||||||
req.Header.Add(string(key), string(value))
|
|
||||||
})
|
|
||||||
|
|
||||||
if c.Context().QueryArgs().Len() > 0 {
|
|
||||||
q := req.URL.Query()
|
|
||||||
c.Context().QueryArgs().VisitAll(func(key, value []byte) {
|
|
||||||
q.Add(string(key), string(value))
|
|
||||||
})
|
|
||||||
req.URL.RawQuery = q.Encode()
|
|
||||||
}
|
|
||||||
|
|
||||||
client := &http.Client{Timeout: scbankQualificationProxyTimeout}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("权益中转请求失败 | target=%s | timeout=%s | cost=%s | err=%v", scbankQualificationProxyURL, scbankQualificationProxyTimeout, time.Since(startAt), err)
|
|
||||||
return c.Status(fiber.StatusBadGateway).SendString(err.Error())
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
for key, values := range resp.Header {
|
|
||||||
for _, value := range values {
|
|
||||||
c.Set(key, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("读取权益中转响应失败 | target=%s | status=%d | err=%v", scbankQualificationProxyURL, resp.StatusCode, err)
|
|
||||||
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("权益中转请求完成 | target=%s | status=%d | cost=%s | headers=%s | body=%s", scbankQualificationProxyURL, resp.StatusCode, time.Since(startAt), formatHeaders(resp.Header), string(body))
|
|
||||||
c.Status(resp.StatusCode)
|
|
||||||
return c.Send(body)
|
|
||||||
}
|
|
||||||
|
|
||||||
func formatHeaders(headers map[string][]string) string {
|
|
||||||
if len(headers) == 0 {
|
|
||||||
return "{}"
|
|
||||||
}
|
|
||||||
data, err := json.Marshal(headers)
|
|
||||||
if err != nil {
|
|
||||||
return "{}"
|
|
||||||
}
|
|
||||||
return string(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func routerSocket(app *fiber.App, chatService *services.ChatService) {
|
func routerSocket(app *fiber.App, chatService *services.ChatService) {
|
||||||
ws := app.Group("ws/v1/")
|
ws := app.Group("ws/v1/")
|
||||||
// WebSocket 路由配置
|
// WebSocket 路由配置
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue