From 2399d79cccfa13f2f992e24654b4ecfd0bd69e69 Mon Sep 17 00:00:00 2001 From: hijiki51 Date: Sat, 6 Aug 2022 09:01:29 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20add=20validation=20and=20chan?= =?UTF-8?q?ge=20binding=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 40c5da8..12c1418 100644 --- a/client.go +++ b/client.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/json" + "errors" "io/ioutil" "log" "net/http" @@ -180,7 +181,19 @@ func (cc *ConohaClient) ObjectStorageRequests() (map[string]float64, error) { } // データ整形 - data := uResp.Request.Data[len(uResp.Request.Data)-3] + if len(uResp.Request.Data) == 0 { + return nil, errors.New("No data") + } + data := uResp.Request.Data[0] + for i, label := range uResp.Request.Schema { + if label == "unixtime" { + for _, v := range uResp.Request.Data { + if data[i] < v[i] { + data = v + } + } + } + } usage := make(map[string]float64) for i, label := range uResp.Request.Schema { usage[label] = data[i]