Skip to content

Commit

Permalink
use map for http response
Browse files Browse the repository at this point in the history
  • Loading branch information
jeangovil authored and senorprogrammer committed Jun 4, 2018
1 parent 5301eae commit 3c49028
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
28 changes: 1 addition & 27 deletions cryptoexchanges/cryptolive/cryptolive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------- */

Expand Down
3 changes: 1 addition & 2 deletions cryptoexchanges/cryptolive/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}

0 comments on commit 3c49028

Please sign in to comment.