-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 695a308
Showing
25 changed files
with
1,306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# These owners will be the default owners for everything in the repo. | ||
* @kataras |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Contributing | ||
|
||
First of all read our [Code of Conduct](https://github.com/kataras/chronos/tree/master/CODE_OF_CONDUCT.md). | ||
|
||
## PR | ||
|
||
1. Open a new [issue](https://github.com/kataras/chronos/issues/new) | ||
* Write version of your local chronos. | ||
* Write version of your local Go programming language. | ||
* Describe your problem, what did you expect to see and what you see instead. | ||
* If it's a feature request, describe your idea as better as you can | ||
* optionally, navigate to the [chat](https://kataras.rocket.chat/channel/chronos) to push other members to participate and share their thoughts about your brilliant idea. | ||
2. Fork the [repository](https://github.com/kataras/chronos). | ||
3. Make your changes. | ||
4. Compare & Push the PR from [here](https://github.com/kataras/chronos/compare). | ||
|
||
## Share | ||
|
||
### Writing | ||
|
||
Write an article about chronos in https://medium.com , https://dev.to or if you're being a hackathon at https://hackernoon.com | ||
|
||
### Social networks | ||
|
||
If you're part of any social network, do a post(or tweet if twitter) about chronos and what you love about it. | ||
|
||
### Work | ||
|
||
Convince your colleagues to try the chronos web framework at dev environment and if they choose to proceed on production, contact with [us](mailto:kataras2006@hotmail.com?subject=chronos%20Production) for further instructions, if you need any help. | ||
|
||
Many young people are choosing chronos for their postgraduate studies as well. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# I'd love to see contributions | ||
|
||
Please link an [issue](https://github.com/katras/chronos/issues) which your PR solves. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.vscode | ||
debug.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: go | ||
os: | ||
- linux | ||
- osx | ||
go: | ||
- go1.8 | ||
- go1.9 | ||
go_import_path: github.com/kataras/chronos | ||
install: | ||
- go get ./... | ||
script: | ||
- go test -v -cover ./... | ||
after_script: | ||
# examples | ||
- cd ./_examples | ||
- go get ./... | ||
- go test -v -cover ./... | ||
- cd ../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# This is the official list of chronos authors for copyright | ||
# purposes. | ||
|
||
Gerasimos Maropoulos <kataras2006@hotmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to making participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, body | ||
size, disability, ethnicity, gender identity and expression, level of experience, | ||
nationality, personal appearance, race, religion, or sexual identity and | ||
orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces | ||
when an individual is representing the project or its community. Examples of | ||
representing a project or community include using an official project e-mail | ||
address, posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. Representation of a project may be | ||
further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team at kataras2006@hotmail.com. All | ||
complaints will be reviewed and investigated and will result in a response that | ||
is deemed necessary and appropriate to the circumstances. The project team is | ||
obligated to maintain confidentiality with regard to the reporter of an incident. | ||
Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||
available at [http://contributor-covenant.org/version/1/4][version] | ||
|
||
[homepage]: http://contributor-covenant.org | ||
[version]: http://contributor-covenant.org/version/1/4/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Changelogs | ||
|
||
## 0.0.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2017 Gerasimos Maropoulos. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of chronos nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# chronos [![build status](https://img.shields.io/travis/kataras/chronos/master.svg?style=flat-square)](https://travis-ci.org/kataras/chronos)[![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/chronos)[![github issues](https://img.shields.io/github/issues/kataras/chronos.svg?style=flat-square)](https://github.com/kataras/chronos/issues?q=is%3Aopen+is%3Aissue)[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/chronos.svg?style=flat-square)](https://github.com/kataras/chronos/issues?q=is%3Aissue+is%3Aclosed)[![release](https://img.shields.io/github/release/kataras/chronos.svg?style=flat-square)](https://github.com/kataras/chronos/releases)[![learn by examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](https://github.com/kataras/chronos/tree/master/_examples)[![docs](https://img.shields.io/badge/chronos%20-godocs-0366d6.svg?style=flat-square)](https://godoc.org/github.com/kataras/chronos) | ||
|
||
Chronos provides an easy way to limit X operations per Y time in accuracy of nanoseconds. | ||
Chronos is a crucial tool when calling external, remote or even internal APIs with rate limits. | ||
|
||
### 📑 Table Of Content | ||
|
||
* [Installation](#-installation) | ||
* [Latest changes](HISTORY.md) | ||
* [Examples](#-learn) | ||
* [Simple native](_examples/native-acquire) | ||
* [Simple http client](_examples/http) | ||
* [Community & Support](#-community) | ||
* [Versioning](#-version) | ||
* [People](#-people) | ||
|
||
### 🚀 Installation | ||
|
||
The only requirement is the [Go Programming Language](https://golang.org/dl/). | ||
|
||
```bash | ||
$ go get -u github.com/kataras/chronos | ||
``` | ||
|
||
> `chronos` has zero third-party dependencies rathen than the Go's standard library. | ||
`Chronos` is very simple to use tool, you just declare the maximum operations(max) and in every Y time | ||
that those operations are allowed to be executed(per). `Chronos` has the accuracy of nanoseconds. | ||
|
||
You can use `chronos#Acquire` anywhere you want, but be careful because it waits/blocks for | ||
availability to be executed. | ||
|
||
```go | ||
import ( | ||
"time" | ||
|
||
"github.com/kataras/chronos" | ||
) | ||
|
||
func main() { | ||
// Allow maximum of 5 MyActions calls | ||
// per 3 seconds. | ||
c := chronos.New(5, 3 * time.Second) | ||
|
||
// The below actions will execute immediately. | ||
MyAction(c) | ||
MyAction(c) | ||
MyAction(c) | ||
MyAction(c) | ||
MyAction(c) | ||
// The below action will execute after 3 seconds from the last call | ||
// or when 3 seconds passed without any c.Acquire call. | ||
MyAction(c) | ||
} | ||
|
||
func MyAction(c *chronos.C) { | ||
<- c.Acquire() | ||
// Do something here... | ||
} | ||
``` | ||
|
||
The `<- c.Acquire()` is blocking when needed, no any further actions neeeded by the end-developer. | ||
|
||
### Helpers | ||
|
||
The [ext](ext) package provides two subpackages; `function` and `http`. Navigate there to learn how they can help you. | ||
|
||
### 📖 Learn | ||
|
||
The awesome `chronos` community is always adding new content to learn from, [_examples](_examples/) is a great place to get started! | ||
|
||
Read the [godocs](https://godoc.org/github.com/kataras/chronos) for a better understanding. | ||
|
||
### 👥 Community | ||
|
||
Join the welcoming community of fellow `chronos` developers in [rocket.chat](https://kataras.rocket.chat/channel/chronos) | ||
|
||
- [Post](https://github.com/kataras/chronos/issues/new) a feature request or report a bug | ||
- :star: and watch the public [repository](https://github.com/kataras/chronos/stargazers), will keep you up to date | ||
- :earth_americas: publish [an article](https://medium.com/search?q=chronos) or share a [tweet](https://twitter.com/hashtag/golang) about your personal experience with `chronos`. | ||
|
||
### 📌 Version | ||
|
||
Current: [0.0.1](VERSION) | ||
|
||
Read more about Semantic Versioning 2.0.0 | ||
|
||
- http://semver.org/ | ||
- https://en.wikipedia.org/wiki/Software_versioning | ||
- https://wiki.debian.org/UpstreamGuide#Releases_and_Versions | ||
|
||
### 🥇 People | ||
|
||
The original author of `chronos` is [@kataras](https://github.com/kataras), you can reach him via; | ||
|
||
- [Medium](https://medium.com/@kataras) | ||
- [Twitter](https://twitter.com/makismaropoulos) | ||
- [Dev.to](https://dev.to/@kataras) | ||
- [Facebook](https://facebook.com/kataras.gopher) | ||
- [Mail](mailto:kataras2006@hotmail.com?subject=Chronos%20I%20need%20some%20help%20please) | ||
|
||
[List of all Authors](AUTHORS) | ||
|
||
[List of all Contributors](https://github.com/kataras/chronos/graphs/contributors) | ||
|
||
## License | ||
|
||
This software is licensed under the open source 3-Clause BSD License. | ||
|
||
You can find the license file [here](LICENSE), for any questions regarding the license please [contact with me](mailto:mailto:kataras2006@hotmail.com?subject=Chronos%20License). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.1:https://github.com/kataras/chronos/blob/master/HISTORY.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/kataras/chronos/ext/http" | ||
) | ||
|
||
type geoInfo struct { | ||
IP string `json:"query,omitempty"` | ||
Country string `json:"country"` | ||
CountryCode string `json:"countryCode"` | ||
Region string `json:"region"` | ||
RegionName string `json:"regionName"` | ||
City string `json:"city"` | ||
Zip string `json:"zip"` | ||
Lat float64 `json:"lat"` | ||
Lon float64 `json:"lon"` | ||
Timezone string `json:"timezone"` | ||
ISP string `json:"isp"` | ||
Org string `json:"org"` | ||
As string `json:"as"` | ||
} | ||
|
||
func main() { | ||
|
||
// The 'ip-api.com' service has a rate limit of 150 requests per minute. | ||
var ( | ||
max uint32 = 150 | ||
per = 1 * time.Minute | ||
) | ||
c := http.New(max, per) | ||
|
||
// This should take 2 minutes, 150 per minute. | ||
for i := 1; i <= 300; i++ { | ||
var ( | ||
info geoInfo | ||
ipToFetch = "165.227.36.244" | ||
) | ||
|
||
requestURL := fmt.Sprintf("http://ip-api.com/json/%s", ipToFetch) | ||
// it may pause for 3-4 seconds at 90-100, this is by the http service, don't be worry | ||
// it will continue until the 150 first, and after a minute from the last fetch | ||
// it will fetch the 150 more, this guards that you will not get banned by the service | ||
// even if you have to fetch thousands of millions of IPs at once, | ||
// chronos will schedule those. | ||
if err := c.ReadJSON(requestURL, &info); err != nil { | ||
// c.Do is like net/http.Client's Do but with the feature of | ||
// chronos' "rate" limiter; maximum operations per x time. | ||
fmt.Println(err.Error()) | ||
continue | ||
} | ||
|
||
fmt.Printf("[%d] %#+v\n", i, info) | ||
} | ||
|
||
} |
Oops, something went wrong.