feat: 增加一个接口转发
This commit is contained in:
parent
91a29e441d
commit
1dd6b306ae
|
|
@ -6,6 +6,8 @@ import (
|
|||
"ai_scheduler/internal/services"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -101,6 +103,51 @@ func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionServi
|
|||
|
||||
// 外部系统支持
|
||||
r.Post("/support/address/ingest/:platform", supportService.AddressIngest) // 通用收获地址提取
|
||||
|
||||
// 转发Python服务
|
||||
r.All("/proxy/fingerprint", forwardToPythonService)
|
||||
}
|
||||
|
||||
func forwardToPythonService(c *fiber.Ctx) error {
|
||||
targetURL := "http://192.168.6.115:10086/fingerprint"
|
||||
|
||||
req, err := http.NewRequest(c.Method(), targetURL, c.Context().Request.BodyStream())
|
||||
if err != nil {
|
||||
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{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
c.Status(resp.StatusCode)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
||||
}
|
||||
|
||||
return c.Send(body)
|
||||
}
|
||||
|
||||
func routerSocket(app *fiber.App, chatService *services.ChatService) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue