Skip to content

Commit

Permalink
fixed api too many requests bug
Browse files Browse the repository at this point in the history
- sleep for 15 seconds
  • Loading branch information
Phillip Miller committed Oct 27, 2021
1 parent 9b917bf commit f6dc3a1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [v0.0.2](https://github.com/mr-pmillz/coinmon-go/tree/v0.0.2) (2021-10-26)

[Full Changelog](https://github.com/mr-pmillz/coinmon-go/compare/v0.0.1...v0.0.2)

## [v0.0.1](https://github.com/mr-pmillz/coinmon-go/tree/v0.0.1) (2021-10-26)

[Full Changelog](https://github.com/mr-pmillz/coinmon-go/compare/v1.0.4...v0.0.1)

## [v1.0.4](https://github.com/mr-pmillz/coinmon-go/tree/v1.0.4) (2021-10-16)

[Full Changelog](https://github.com/mr-pmillz/coinmon-go/compare/v1.0.3...v1.0.4)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/mr-pmillz/coinmon-go?style=plastic)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/mr-pmillz/coinmon-go?style=plastic)
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/mr-pmillz/coinmon-go?style=plastic)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/12750b2a6fa44b429f8a3f64d3e7f1b6)](https://www.codacy.com/gh/mr-pmillz/coinmon-go/dashboard?utm_source=github.com&utm_medium=referral&utm_content=mr-pmillz/coinmon-go&utm_campaign=Badge_Coverage)

Table of Contents
=================
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ func getJSON(url string, target interface{}) error {
return err
}
defer r.Body.Close()
if r.StatusCode == 429 {
fmt.Printf("Sleeping for 15 seconds, too many requests HTTP Response: %d\n", r.StatusCode)
time.Sleep(time.Second * 15)
req, err := myClient.Get(url)
if err != nil {
return err
}
defer req.Body.Close()
return json.NewDecoder(req.Body).Decode(target)
}

return json.NewDecoder(r.Body).Decode(target)
}
Expand Down

0 comments on commit f6dc3a1

Please sign in to comment.