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
5301eae6bf
commit
3c4902835e
@ -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 -------------------- */
|
||||
|
||||
|
@ -174,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