This commit is contained in:
2026-04-13 13:14:14 +08:00
parent 35b7fad8ab
commit 754a91e5b3
6 changed files with 231 additions and 9 deletions

15
internal/impl.go Normal file
View File

@@ -0,0 +1,15 @@
package internal
import (
"git.apinb.com/bsm-sdk/core/cache/redis"
"git.apinb.com/bsm-sdk/core/with"
)
var (
CacheUrl = "redis://null:Weidong2023~!@139.224.247.176:19379/0"
RedisService *redis.RedisClient
)
func NewImpl() {
RedisService = with.RedisCache(CacheUrl) // redis cache
}

View File

@@ -1,23 +1,57 @@
package internal
import (
"encoding/json"
"log"
"net/http"
"time"
"git.apinb.com/bsm-sdk/core/utils"
"github.com/gin-gonic/gin"
)
func TickRecv(c *gin.Context) {
data := map[string]any{}
log.Println("TickRecv called")
stocks := GetAllowStocks()
if len(stocks) == 0 {
c.JSON(http.StatusOK, gin.H{
"status": "OK",
"num": len(stocks),
})
return
}
data := map[string]any{}
// Gin 的 Bind 方法会自动根据 Content-Type 解析
// 当 Content-Type 为 application/msgpack 时,它会调用 MsgPack 解析器
if err := c.Bind(&data); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
for key, value := range data {
if utils.ArrayInString(key, stocks) {
RedisService.Set(key, value, 1*time.Hour)
}
}
// 处理数据...
c.JSON(http.StatusOK, gin.H{
"status": "OK",
})
}
func GetAllowStocks() []string {
result, err := utils.HttpGet("http://139.224.247.176:13499/a/pass_codes")
if err != nil {
log.Println("Error: Http Get pass_codes", err.Error())
return nil
}
var stocks []string
err = json.Unmarshal(result, &stocks)
if err != nil {
log.Println("Error: Json Unmarshal pass_codes", err.Error())
return nil
}
return stocks
}