Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
remove log
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Sep 12, 2017
1 parent 03bfbbb commit 9066597
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
17 changes: 6 additions & 11 deletions coinmarketcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)

Expand All @@ -24,7 +23,7 @@ func GetMarketData() (GlobalMarketData, error) {
var data GlobalMarketData
err = json.Unmarshal(resp, &data)
if err != nil {
log.Println(err)
return GlobalMarketData{}, err
}

return data, nil
Expand All @@ -35,13 +34,11 @@ func GetCoinData(coin string) (Coin, error) {
url = fmt.Sprintf("%s/ticker/%s", baseUrl, coin)
resp, err := makeReq(url)
if err != nil {
log.Println(err)
return Coin{}, err
}
var data []Coin
err = json.Unmarshal(resp, &data)
if err != nil {
log.Println(err)
return Coin{}, err
}

Expand All @@ -61,7 +58,7 @@ func GetAllCoinData(limit int) (map[string]Coin, error) {
var data []Coin
err = json.Unmarshal(resp, &data)
if err != nil {
log.Println(err)
return nil, err
}
// creating map from the array
allCoins := make(map[string]Coin)
Expand All @@ -77,13 +74,11 @@ func GetCoinGraphData(coin string, start int64, end int64) (CoinGraph, error) {
url = fmt.Sprintf("%s/%s/%d/%d", graphUrl, coin, start*1000, end*1000)
resp, err := makeReq(url)
if err != nil {
log.Println(err)
return CoinGraph{}, err
}
var data CoinGraph
err = json.Unmarshal(resp, &data)
if err != nil {
log.Println(err)
return CoinGraph{}, err
}

Expand All @@ -95,12 +90,12 @@ func doReq(req *http.Request) ([]byte, error) {
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Println(err)
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println(err)
return nil, err
}
if 200 != resp.StatusCode {
return nil, fmt.Errorf("%s", body)
Expand All @@ -113,11 +108,11 @@ func doReq(req *http.Request) ([]byte, error) {
func makeReq(url string) ([]byte, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Println(err)
return nil, err
}
resp, err := doReq(req)
if err != nil {
log.Println(err)
return nil, err
}

return resp, err
Expand Down
4 changes: 2 additions & 2 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func main() {
if err != nil {
log.Println(err)
} else {
fmt.Println(coinIfo)

fmt.Println(coinInfo)
}

// Get top 10 coins
top10, err := coinApi.GetAllCoinData(10)
if err != nil {
Expand Down

0 comments on commit 9066597

Please sign in to comment.