{"action":"created","comment":{"url":"https://api.github.com/repos/pressly/chi/pulls/comments/47181155","id":47181155,"diff_hunk":"@@ -0,0 +1,105 @@\n+package middleware\n+\n+import (\n+\t\"net/http\"\n+\t\"time\"\n+\n+\t\"github.com/pressly/chi\"\n+\t\"golang.org/x/net/context\"\n+)\n+\n+const (\n+\terrCapacityExceeded = \"Server capacity exceeded.\"\n+\terrTimedOut         = \"Timed out while waiting for a pending request to complete.\"\n+\terrContextCanceled  = \"Context was canceled.\"\n+)\n+\n+var (\n+\tdefaultThrottleTimeout = time.Second * 60\n+)\n+\n+// Throttle is a middleware that limits number of currently processed requests\n+// at a time.\n+func Throttle(limit int) func(chi.Handler) chi.Handler {\n+\treturn ThrottleBacklog(limit, 0, defaultThrottleTimeout)\n+}\n+\n+// ThrottleBacklog is a middleware that limits number of currently processed\n+// requests at a time and provides a backlog for holding a finite number of\n+// pending requests.\n+func ThrottleBacklog(limit int, backloglimit int, timeout time.Duration) func(chi.Handler) chi.Handler {","path":"middleware/throttler.go","position":30,"original_position":30,"commit_id":"feb09735322758d2be9b8ef6bfc9cd3a9489a268","original_commit_id":"feb09735322758d2be9b8ef6bfc9cd3a9489a268","user":{"login":"pkieltyka","id":18831,"avatar_url":"https://avatars.githubusercontent.com/u/18831?v=3","gravatar_id":"","url":"https://api.github.com/users/pkieltyka","html_url":"https://github.com/pkieltyka","followers_url":"https://api.github.com/users/pkieltyka/followers","following_url":"https://api.github.com/users/pkieltyka/following{/other_user}","gists_url":"https://api.github.com/users/pkieltyka/gists{/gist_id}","starred_url":"https://api.github.com/users/pkieltyka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkieltyka/subscriptions","organizations_url":"https://api.github.com/users/pkieltyka/orgs","repos_url":"https://api.github.com/users/pkieltyka/repos","events_url":"https://api.github.com/users/pkieltyka/events{/privacy}","received_events_url":"https://api.github.com/users/pkieltyka/received_events","type":"User","site_admin":false},"body":"I kind of prefer `backlogLimit` over `backloglimit`","created_at":"2015-12-10T02:02:37Z","updated_at":"2015-12-10T02:02:37Z","html_url":"https://github.com/pressly/chi/pull/26#discussion_r47181155","pull_request_url":"https://api.github.com/repos/pressly/chi/pulls/26","_links":{"self":{"href":"https://api.github.com/repos/pressly/chi/pulls/comments/47181155"},"html":{"href":"https://github.com/pressly/chi/pull/26#discussion_r47181155"},"pull_request":{"href":"https://api.github.com/repos/pressly/chi/pulls/26"}}},"pull_request":{"url":"https://api.github.com/repos/pressly/chi/pulls/26","id":53137335,"html_url":"https://github.com/pressly/chi/pull/26","diff_url":"https://github.com/pressly/chi/pull/26.diff","patch_url":"https://github.com/pressly/chi/pull/26.patch","issue_url":"https://api.github.com/repos/pressly/chi/issues/26","number":26,"state":"open","locked":false,"title":"Adding backlog to throttler middleware","user":{"login":"xiam","id":385670,"avatar_url":"https://avatars.githubusercontent.com/u/385670?v=3","gravatar_id":"","url":"https://api.github.com/users/xiam","html_url":"https://github.com/xiam","followers_url":"https://api.github.com/users/xiam/followers","following_url":"https://api.github.com/users/xiam/following{/other_user}","gists_url":"https://api.github.com/users/xiam/gists{/gist_id}","starred_url":"https://api.github.com/users/xiam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiam/subscriptions","organizations_url":"https://api.github.com/users/xiam/orgs","repos_url":"https://api.github.com/users/xiam/repos","events_url":"https://api.github.com/users/xiam/events{/privacy}","received_events_url":"https://api.github.com/users/xiam/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-09T15:54:17Z","updated_at":"2015-12-10T02:02:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"90e091e9ab749a72566bfe15448e7744584cb327","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pressly/chi/pulls/26/commits","review_comments_url":"https://api.github.com/repos/pressly/chi/pulls/26/comments","review_comment_url":"https://api.github.com/repos/pressly/chi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pressly/chi/issues/26/comments","statuses_url":"https://api.github.com/repos/pressly/chi/statuses/feb09735322758d2be9b8ef6bfc9cd3a9489a268","head":{"label":"pressly:issue-25","ref":"issue-25","sha":"feb09735322758d2be9b8ef6bfc9cd3a9489a268","user":{"login":"pressly","id":18835,"avatar_url":"https://avatars.githubusercontent.com/u/18835?v=3","gravatar_id":"","url":"https://api.github.com/users/pressly","html_url":"https://github.com/pressly","followers_url":"https://api.github.com/users/pressly/followers","following_url":"https://api.github.com/users/pressly/following{/other_user}","gists_url":"https://api.github.com/users/pressly/gists{/gist_id}","starred_url":"https://api.github.com/users/pressly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pressly/subscriptions","organizations_url":"https://api.github.com/users/pressly/orgs","repos_url":"https://api.github.com/users/pressly/repos","events_url":"https://api.github.com/users/pressly/events{/privacy}","received_events_url":"https://api.github.com/users/pressly/received_events","type":"Organization","site_admin":false},"repo":{"id":44344606,"name":"chi","full_name":"pressly/chi","owner":{"login":"pressly","id":18835,"avatar_url":"https://avatars.githubusercontent.com/u/18835?v=3","gravatar_id":"","url":"https://api.github.com/users/pressly","html_url":"https://github.com/pressly","followers_url":"https://api.github.com/users/pressly/followers","following_url":"https://api.github.com/users/pressly/following{/other_user}","gists_url":"https://api.github.com/users/pressly/gists{/gist_id}","starred_url":"https://api.github.com/users/pressly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pressly/subscriptions","organizations_url":"https://api.github.com/users/pressly/orgs","repos_url":"https://api.github.com/users/pressly/repos","events_url":"https://api.github.com/users/pressly/events{/privacy}","received_events_url":"https://api.github.com/users/pressly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pressly/chi","description":"small, fast and expressive router / mux for Go HTTP services built with net/context","fork":false,"url":"https://api.github.com/repos/pressly/chi","forks_url":"https://api.github.com/repos/pressly/chi/forks","keys_url":"https://api.github.com/repos/pressly/chi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pressly/chi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pressly/chi/teams","hooks_url":"https://api.github.com/repos/pressly/chi/hooks","issue_events_url":"https://api.github.com/repos/pressly/chi/issues/events{/number}","events_url":"https://api.github.com/repos/pressly/chi/events","assignees_url":"https://api.github.com/repos/pressly/chi/assignees{/user}","branches_url":"https://api.github.com/repos/pressly/chi/branches{/branch}","tags_url":"https://api.github.com/repos/pressly/chi/tags","blobs_url":"https://api.github.com/repos/pressly/chi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pressly/chi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pressly/chi/git/refs{/sha}","trees_url":"https://api.github.com/repos/pressly/chi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pressly/chi/statuses/{sha}","languages_url":"https://api.github.com/repos/pressly/chi/languages","stargazers_url":"https://api.github.com/repos/pressly/chi/stargazers","contributors_url":"https://api.github.com/repos/pressly/chi/contributors","subscribers_url":"https://api.github.com/repos/pressly/chi/subscribers","subscription_url":"https://api.github.com/repos/pressly/chi/subscription","commits_url":"https://api.github.com/repos/pressly/chi/commits{/sha}","git_commits_url":"https://api.github.com/repos/pressly/chi/git/commits{/sha}","comments_url":"https://api.github.com/repos/pressly/chi/comments{/number}","issue_comment_url":"https://api.github.com/repos/pressly/chi/issues/comments{/number}","contents_url":"https://api.github.com/repos/pressly/chi/contents/{+path}","compare_url":"https://api.github.com/repos/pressly/chi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pressly/chi/merges","archive_url":"https://api.github.com/repos/pressly/chi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pressly/chi/downloads","issues_url":"https://api.github.com/repos/pressly/chi/issues{/number}","pulls_url":"https://api.github.com/repos/pressly/chi/pulls{/number}","milestones_url":"https://api.github.com/repos/pressly/chi/milestones{/number}","notifications_url":"https://api.github.com/repos/pressly/chi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pressly/chi/labels{/name}","releases_url":"https://api.github.com/repos/pressly/chi/releases{/id}","created_at":"2015-10-15T20:46:29Z","updated_at":"2015-12-06T14:38:56Z","pushed_at":"2015-12-10T01:14:18Z","git_url":"git://github.com/pressly/chi.git","ssh_url":"git@github.com:pressly/chi.git","clone_url":"https://github.com/pressly/chi.git","svn_url":"https://github.com/pressly/chi","homepage":"","size":115,"stargazers_count":234,"watchers_count":234,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":5,"forks":10,"open_issues":5,"watchers":234,"default_branch":"master"}},"base":{"label":"pressly:master","ref":"master","sha":"3202fdec0946b160e2a1c1a1fa38174fdfc6cec0","user":{"login":"pressly","id":18835,"avatar_url":"https://avatars.githubusercontent.com/u/18835?v=3","gravatar_id":"","url":"https://api.github.com/users/pressly","html_url":"https://github.com/pressly","followers_url":"https://api.github.com/users/pressly/followers","following_url":"https://api.github.com/users/pressly/following{/other_user}","gists_url":"https://api.github.com/users/pressly/gists{/gist_id}","starred_url":"https://api.github.com/users/pressly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pressly/subscriptions","organizations_url":"https://api.github.com/users/pressly/orgs","repos_url":"https://api.github.com/users/pressly/repos","events_url":"https://api.github.com/users/pressly/events{/privacy}","received_events_url":"https://api.github.com/users/pressly/received_events","type":"Organization","site_admin":false},"repo":{"id":44344606,"name":"chi","full_name":"pressly/chi","owner":{"login":"pressly","id":18835,"avatar_url":"https://avatars.githubusercontent.com/u/18835?v=3","gravatar_id":"","url":"https://api.github.com/users/pressly","html_url":"https://github.com/pressly","followers_url":"https://api.github.com/users/pressly/followers","following_url":"https://api.github.com/users/pressly/following{/other_user}","gists_url":"https://api.github.com/users/pressly/gists{/gist_id}","starred_url":"https://api.github.com/users/pressly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pressly/subscriptions","organizations_url":"https://api.github.com/users/pressly/orgs","repos_url":"https://api.github.com/users/pressly/repos","events_url":"https://api.github.com/users/pressly/events{/privacy}","received_events_url":"https://api.github.com/users/pressly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pressly/chi","description":"small, fast and expressive router / mux for Go HTTP services built with net/context","fork":false,"url":"https://api.github.com/repos/pressly/chi","forks_url":"https://api.github.com/repos/pressly/chi/forks","keys_url":"https://api.github.com/repos/pressly/chi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pressly/chi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pressly/chi/teams","hooks_url":"https://api.github.com/repos/pressly/chi/hooks","issue_events_url":"https://api.github.com/repos/pressly/chi/issues/events{/number}","events_url":"https://api.github.com/repos/pressly/chi/events","assignees_url":"https://api.github.com/repos/pressly/chi/assignees{/user}","branches_url":"https://api.github.com/repos/pressly/chi/branches{/branch}","tags_url":"https://api.github.com/repos/pressly/chi/tags","blobs_url":"https://api.github.com/repos/pressly/chi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pressly/chi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pressly/chi/git/refs{/sha}","trees_url":"https://api.github.com/repos/pressly/chi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pressly/chi/statuses/{sha}","languages_url":"https://api.github.com/repos/pressly/chi/languages","stargazers_url":"https://api.github.com/repos/pressly/chi/stargazers","contributors_url":"https://api.github.com/repos/pressly/chi/contributors","subscribers_url":"https://api.github.com/repos/pressly/chi/subscribers","subscription_url":"https://api.github.com/repos/pressly/chi/subscription","commits_url":"https://api.github.com/repos/pressly/chi/commits{/sha}","git_commits_url":"https://api.github.com/repos/pressly/chi/git/commits{/sha}","comments_url":"https://api.github.com/repos/pressly/chi/comments{/number}","issue_comment_url":"https://api.github.com/repos/pressly/chi/issues/comments{/number}","contents_url":"https://api.github.com/repos/pressly/chi/contents/{+path}","compare_url":"https://api.github.com/repos/pressly/chi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pressly/chi/merges","archive_url":"https://api.github.com/repos/pressly/chi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pressly/chi/downloads","issues_url":"https://api.github.com/repos/pressly/chi/issues{/number}","pulls_url":"https://api.github.com/repos/pressly/chi/pulls{/number}","milestones_url":"https://api.github.com/repos/pressly/chi/milestones{/number}","notifications_url":"https://api.github.com/repos/pressly/chi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pressly/chi/labels{/name}","releases_url":"https://api.github.com/repos/pressly/chi/releases{/id}","created_at":"2015-10-15T20:46:29Z","updated_at":"2015-12-06T14:38:56Z","pushed_at":"2015-12-10T01:14:18Z","git_url":"git://github.com/pressly/chi.git","ssh_url":"git@github.com:pressly/chi.git","clone_url":"https://github.com/pressly/chi.git","svn_url":"https://github.com/pressly/chi","homepage":"","size":115,"stargazers_count":234,"watchers_count":234,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":5,"forks":10,"open_issues":5,"watchers":234,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pressly/chi/pulls/26"},"html":{"href":"https://github.com/pressly/chi/pull/26"},"issue":{"href":"https://api.github.com/repos/pressly/chi/issues/26"},"comments":{"href":"https://api.github.com/repos/pressly/chi/issues/26/comments"},"review_comments":{"href":"https://api.github.com/repos/pressly/chi/pulls/26/comments"},"review_comment":{"href":"https://api.github.com/repos/pressly/chi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pressly/chi/pulls/26/commits"},"statuses":{"href":"https://api.github.com/repos/pressly/chi/statuses/feb09735322758d2be9b8ef6bfc9cd3a9489a268"}}}}