mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
use map for http response
This commit is contained in:
parent
2780992851
commit
c2d2197ed0
@ -15,33 +15,7 @@ type toCurrency struct {
|
||||
price float32
|
||||
}
|
||||
|
||||
type cResponse struct {
|
||||
BTC float32 `json:"BTC"`
|
||||
HBZ float32 `json:"HBZ"`
|
||||
ETH float32 `json:"ETH"`
|
||||
EOS float32 `json:"EOS"`
|
||||
BCH float32 `json:"BCH"`
|
||||
TRX float32 `json:"TRX"`
|
||||
XRP float32 `json:"XRP"`
|
||||
LTC float32 `json:"LTC"`
|
||||
ETC float32 `json:"ETC"`
|
||||
ADA float32 `json:"ADA"`
|
||||
CMT float32 `json:"CMT"`
|
||||
DASH float32 `json:"DASH"`
|
||||
ZEC float32 `json:"ZEC"`
|
||||
IOT float32 `json:"IOT"`
|
||||
ONT float32 `json:"ONT"`
|
||||
NEO float32 `json:"NEO"`
|
||||
BTG float32 `json:"BTG"`
|
||||
LSK float32 `json:"LSK"`
|
||||
ELA float32 `json:"ELA"`
|
||||
DTA float32 `json:"DTA"`
|
||||
NANO float32 `json:"NANO"`
|
||||
WTC float32 `json:"WTC"`
|
||||
DOGE float32 `json:"DOGE"`
|
||||
USD float32 `json:"USD"`
|
||||
EUR float32 `json:"EUR"`
|
||||
}
|
||||
type cResponse map[string]float32
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
|
@ -3,7 +3,6 @@ package cryptolive
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"net/http"
|
||||
@ -175,8 +174,7 @@ func makeRequest(currency *fromCurrency) *http.Request {
|
||||
}
|
||||
|
||||
func setPrices(response *cResponse, currencry *fromCurrency) {
|
||||
responseRef := reflect.Indirect(reflect.ValueOf(response))
|
||||
for idx, toCurrency := range currencry.to {
|
||||
currencry.to[idx].price = responseRef.FieldByName(toCurrency.name).Interface().(float32)
|
||||
currencry.to[idx].price = (*response)[toCurrency.name]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user