123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/hongze_edb_lib/utils"
- "github.com/rdlucklib/rdluck_tools/http"
- )
- type EdbDataFromLt struct {
- Close map[int64]interface{} `json:"CLOSE"`
- Value map[int64]interface{} `json:"VALUE"`
- }
- // GetEdbDataFromLt 获取路透数据
- func GetEdbDataFromLt(edbCode, startDate, endDate string) (dataList map[int64]interface{}, err error) {
- if utils.Hz_LT_Data_Url == `` {
- err = errors.New("路透社接口未配置")
- return
- }
- dataList = make(map[int64]interface{})
- ltUrl := utils.Hz_LT_Data_Url + `edbInfo/ek?EdbCode=%s&StartDate=%s&EndDate=%s`
- ltUrl = fmt.Sprintf(ltUrl, edbCode, startDate, endDate)
- utils.FileLog.Info("ltUrl:%s", ltUrl)
- body, err := http.Get(ltUrl)
- utils.FileLog.Info("lt result:%s", string(body))
- if err != nil {
- return
- }
- item := new(EdbDataFromLt)
- err = json.Unmarshal(body, &item)
- if err != nil {
- return
- }
- if len(item.Close) > 0 {
- dataList = item.Close
- } else {
- dataList = item.Value
- }
- return
- }
|