feat(hook): Add hook module to help decouple some specific logic (#784)

This commit is contained in:
Shui
2025-11-08 20:02:30 -05:00
committed by GitHub
parent 52b0bfe1d2
commit 631fb62d21
12 changed files with 466 additions and 35 deletions

View File

@@ -6,6 +6,7 @@ import (
"io"
"log"
"net/http"
"nofx/hook"
"strconv"
"time"
)
@@ -19,10 +20,18 @@ type APIClient struct {
}
func NewAPIClient() *APIClient {
client := &http.Client{
Timeout: 30 * time.Second,
}
hookRes := hook.HookExec[hook.SetHttpClientResult](hook.SET_HTTP_CLIENT, client)
if hookRes != nil && hookRes.Error() == nil {
log.Printf("使用Hook设置的HTTP客户端")
client = hookRes.GetResult()
}
return &APIClient{
client: &http.Client{
Timeout: 30 * time.Second,
},
client: client,
}
}
@@ -74,6 +83,7 @@ func (c *APIClient) GetKlines(symbol, interval string, limit int) ([]Kline, erro
var klineResponses []KlineResponse
err = json.Unmarshal(body, &klineResponses)
if err != nil {
log.Printf("获取K线数据失败,响应内容: %s", string(body))
return nil, err
}