package services import ( "encoding/json" "errors" "fmt" "github.com/rdlucklib/rdluck_tools/http" "hongze/hongze_edb_lib/utils" ) type EdbDataFromThs struct { DataVol int64 `json:"dataVol"` Errmsg string `json:"errmsg"` Errorcode int64 `json:"errorcode"` Perf interface{} `json:"perf"` Tables []struct { ID []string `json:"id"` Time []string `json:"time"` Value []float64 `json:"value"` } `json:"tables"` } func GetEdbDataFromThs(edbCode, startDate, endDate string) (item *EdbDataFromThs, err error) { thsUrl := utils.Hz_Ths_Data_Url + `edbInfo/ths?EdbCode=%s&StartDate=%s&EndDate=%s` thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate) utils.FileLog.Info("thsUrl:" + thsUrl) body, err := http.Get(thsUrl) utils.FileLog.Info("ths result:" + string(body)) if err != nil { err = errors.New(" Err:" + err.Error() + ";result:" + string(body)) return } item = new(EdbDataFromThs) err = json.Unmarshal(body, &item) if err != nil { err = errors.New("GetEdbDataFromThs json.Unmarshal Err:" + err.Error()) return } if item.Errorcode != 0 { err = errors.New(string(body)) return } return item, nil }