{"action":"created","comment":{"url":"https://api.github.com/repos/go-statsd/statsd/pulls/comments/25178426","id":25178426,"diff_hunk":"@@ -0,0 +1,76 @@\n+// Copyright (c) 2015 Canonical Ltd.\n+\n+// Package httpstats provides middleware for HTTP statistics collection.\n+package httpstats\n+\n+import (\n+\t\"fmt\"\n+\t\"net/http\"\n+\n+\t\"gopkg.in/statsd.v0\"\n+)\n+\n+// Stats returns an http.Handler that wraps the given one with HTTP statistics\n+// collection.\n+func Stats(client *statsd.Client, prefix string, next http.Handler) http.Handler {\n+\tif prefix == \"\" {\n+\t\tprefix = \"http\"\n+\t}\n+\treturn &statsHandler{\n+\t\tclient: client,\n+\t\tprefix: prefix,\n+\t\tnext:   next,\n+\t}\n+}\n+\n+type statsHandler struct {\n+\tclient *statsd.Client\n+\tprefix string\n+\tnext   http.Handler\n+}\n+\n+func (s *statsHandler) name(name string) string {\n+\treturn fmt.Sprintf(\"%s.%s\", s.prefix, name)","path":"httpstats/middleware.go","position":33,"original_position":33,"commit_id":"2a0dd4543eea14f4ab48da298a0718c43700b2ca","original_commit_id":"2a0dd4543eea14f4ab48da298a0718c43700b2ca","user":{"login":"rogpeppe","id":66491,"avatar_url":"https://avatars.githubusercontent.com/u/66491?v=3","gravatar_id":"","url":"https://api.github.com/users/rogpeppe","html_url":"https://github.com/rogpeppe","followers_url":"https://api.github.com/users/rogpeppe/followers","following_url":"https://api.github.com/users/rogpeppe/following{/other_user}","gists_url":"https://api.github.com/users/rogpeppe/gists{/gist_id}","starred_url":"https://api.github.com/users/rogpeppe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rogpeppe/subscriptions","organizations_url":"https://api.github.com/users/rogpeppe/orgs","repos_url":"https://api.github.com/users/rogpeppe/repos","events_url":"https://api.github.com/users/rogpeppe/events{/privacy}","received_events_url":"https://api.github.com/users/rogpeppe/received_events","type":"User","site_admin":false},"body":"Rather than doing this on every HTTP request, you might want to pre-calculate the names and put them into statsHandler fields. That'll save at least 7 allocs per http request.","created_at":"2015-02-23T16:38:45Z","updated_at":"2015-02-23T16:38:45Z","html_url":"https://github.com/go-statsd/statsd/pull/1#discussion_r25178426","pull_request_url":"https://api.github.com/repos/go-statsd/statsd/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/go-statsd/statsd/pulls/comments/25178426"},"html":{"href":"https://github.com/go-statsd/statsd/pull/1#discussion_r25178426"},"pull_request":{"href":"https://api.github.com/repos/go-statsd/statsd/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/go-statsd/statsd/pulls/1","id":29492169,"html_url":"https://github.com/go-statsd/statsd/pull/1","diff_url":"https://github.com/go-statsd/statsd/pull/1.diff","patch_url":"https://github.com/go-statsd/statsd/pull/1.patch","issue_url":"https://api.github.com/repos/go-statsd/statsd/issues/1","number":1,"state":"open","locked":false,"title":"Add http statistics-collecting middleware.","user":{"login":"cmars","id":23741,"avatar_url":"https://avatars.githubusercontent.com/u/23741?v=3","gravatar_id":"","url":"https://api.github.com/users/cmars","html_url":"https://github.com/cmars","followers_url":"https://api.github.com/users/cmars/followers","following_url":"https://api.github.com/users/cmars/following{/other_user}","gists_url":"https://api.github.com/users/cmars/gists{/gist_id}","starred_url":"https://api.github.com/users/cmars/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmars/subscriptions","organizations_url":"https://api.github.com/users/cmars/orgs","repos_url":"https://api.github.com/users/cmars/repos","events_url":"https://api.github.com/users/cmars/events{/privacy}","received_events_url":"https://api.github.com/users/cmars/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-18T00:41:10Z","updated_at":"2015-02-23T16:38:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ae93c68110a636b46004820a642aeec5d74e94b0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/go-statsd/statsd/pulls/1/commits","review_comments_url":"https://api.github.com/repos/go-statsd/statsd/pulls/1/comments","review_comment_url":"https://api.github.com/repos/go-statsd/statsd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/go-statsd/statsd/issues/1/comments","statuses_url":"https://api.github.com/repos/go-statsd/statsd/statuses/2a0dd4543eea14f4ab48da298a0718c43700b2ca","head":{"label":"cmars:001-httpstats","ref":"001-httpstats","sha":"2a0dd4543eea14f4ab48da298a0718c43700b2ca","user":{"login":"cmars","id":23741,"avatar_url":"https://avatars.githubusercontent.com/u/23741?v=3","gravatar_id":"","url":"https://api.github.com/users/cmars","html_url":"https://github.com/cmars","followers_url":"https://api.github.com/users/cmars/followers","following_url":"https://api.github.com/users/cmars/following{/other_user}","gists_url":"https://api.github.com/users/cmars/gists{/gist_id}","starred_url":"https://api.github.com/users/cmars/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmars/subscriptions","organizations_url":"https://api.github.com/users/cmars/orgs","repos_url":"https://api.github.com/users/cmars/repos","events_url":"https://api.github.com/users/cmars/events{/privacy}","received_events_url":"https://api.github.com/users/cmars/received_events","type":"User","site_admin":false},"repo":{"id":30676828,"name":"statsd","full_name":"cmars/statsd","owner":{"login":"cmars","id":23741,"avatar_url":"https://avatars.githubusercontent.com/u/23741?v=3","gravatar_id":"","url":"https://api.github.com/users/cmars","html_url":"https://github.com/cmars","followers_url":"https://api.github.com/users/cmars/followers","following_url":"https://api.github.com/users/cmars/following{/other_user}","gists_url":"https://api.github.com/users/cmars/gists{/gist_id}","starred_url":"https://api.github.com/users/cmars/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmars/subscriptions","organizations_url":"https://api.github.com/users/cmars/orgs","repos_url":"https://api.github.com/users/cmars/repos","events_url":"https://api.github.com/users/cmars/events{/privacy}","received_events_url":"https://api.github.com/users/cmars/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cmars/statsd","description":"A client library for statsd written in Go","fork":true,"url":"https://api.github.com/repos/cmars/statsd","forks_url":"https://api.github.com/repos/cmars/statsd/forks","keys_url":"https://api.github.com/repos/cmars/statsd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cmars/statsd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cmars/statsd/teams","hooks_url":"https://api.github.com/repos/cmars/statsd/hooks","issue_events_url":"https://api.github.com/repos/cmars/statsd/issues/events{/number}","events_url":"https://api.github.com/repos/cmars/statsd/events","assignees_url":"https://api.github.com/repos/cmars/statsd/assignees{/user}","branches_url":"https://api.github.com/repos/cmars/statsd/branches{/branch}","tags_url":"https://api.github.com/repos/cmars/statsd/tags","blobs_url":"https://api.github.com/repos/cmars/statsd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cmars/statsd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cmars/statsd/git/refs{/sha}","trees_url":"https://api.github.com/repos/cmars/statsd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cmars/statsd/statuses/{sha}","languages_url":"https://api.github.com/repos/cmars/statsd/languages","stargazers_url":"https://api.github.com/repos/cmars/statsd/stargazers","contributors_url":"https://api.github.com/repos/cmars/statsd/contributors","subscribers_url":"https://api.github.com/repos/cmars/statsd/subscribers","subscription_url":"https://api.github.com/repos/cmars/statsd/subscription","commits_url":"https://api.github.com/repos/cmars/statsd/commits{/sha}","git_commits_url":"https://api.github.com/repos/cmars/statsd/git/commits{/sha}","comments_url":"https://api.github.com/repos/cmars/statsd/comments{/number}","issue_comment_url":"https://api.github.com/repos/cmars/statsd/issues/comments{/number}","contents_url":"https://api.github.com/repos/cmars/statsd/contents/{+path}","compare_url":"https://api.github.com/repos/cmars/statsd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cmars/statsd/merges","archive_url":"https://api.github.com/repos/cmars/statsd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cmars/statsd/downloads","issues_url":"https://api.github.com/repos/cmars/statsd/issues{/number}","pulls_url":"https://api.github.com/repos/cmars/statsd/pulls{/number}","milestones_url":"https://api.github.com/repos/cmars/statsd/milestones{/number}","notifications_url":"https://api.github.com/repos/cmars/statsd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cmars/statsd/labels{/name}","releases_url":"https://api.github.com/repos/cmars/statsd/releases{/id}","created_at":"2015-02-12T00:11:51Z","updated_at":"2015-02-20T17:31:20Z","pushed_at":"2015-02-23T04:43:16Z","git_url":"git://github.com/cmars/statsd.git","ssh_url":"git@github.com:cmars/statsd.git","clone_url":"https://github.com/cmars/statsd.git","svn_url":"https://github.com/cmars/statsd","homepage":"http://godoc.org/gopkg.in/statsd.v0","size":168,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"go-statsd:master","ref":"master","sha":"526dee2ede99db30e17d0dfe99e418f37a5213cd","user":{"login":"go-statsd","id":10968721,"avatar_url":"https://avatars.githubusercontent.com/u/10968721?v=3","gravatar_id":"","url":"https://api.github.com/users/go-statsd","html_url":"https://github.com/go-statsd","followers_url":"https://api.github.com/users/go-statsd/followers","following_url":"https://api.github.com/users/go-statsd/following{/other_user}","gists_url":"https://api.github.com/users/go-statsd/gists{/gist_id}","starred_url":"https://api.github.com/users/go-statsd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-statsd/subscriptions","organizations_url":"https://api.github.com/users/go-statsd/orgs","repos_url":"https://api.github.com/users/go-statsd/repos","events_url":"https://api.github.com/users/go-statsd/events{/privacy}","received_events_url":"https://api.github.com/users/go-statsd/received_events","type":"Organization","site_admin":false},"repo":{"id":30679118,"name":"statsd","full_name":"go-statsd/statsd","owner":{"login":"go-statsd","id":10968721,"avatar_url":"https://avatars.githubusercontent.com/u/10968721?v=3","gravatar_id":"","url":"https://api.github.com/users/go-statsd","html_url":"https://github.com/go-statsd","followers_url":"https://api.github.com/users/go-statsd/followers","following_url":"https://api.github.com/users/go-statsd/following{/other_user}","gists_url":"https://api.github.com/users/go-statsd/gists{/gist_id}","starred_url":"https://api.github.com/users/go-statsd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-statsd/subscriptions","organizations_url":"https://api.github.com/users/go-statsd/orgs","repos_url":"https://api.github.com/users/go-statsd/repos","events_url":"https://api.github.com/users/go-statsd/events{/privacy}","received_events_url":"https://api.github.com/users/go-statsd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/go-statsd/statsd","description":"A client library for statsd written in Go","fork":true,"url":"https://api.github.com/repos/go-statsd/statsd","forks_url":"https://api.github.com/repos/go-statsd/statsd/forks","keys_url":"https://api.github.com/repos/go-statsd/statsd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/go-statsd/statsd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/go-statsd/statsd/teams","hooks_url":"https://api.github.com/repos/go-statsd/statsd/hooks","issue_events_url":"https://api.github.com/repos/go-statsd/statsd/issues/events{/number}","events_url":"https://api.github.com/repos/go-statsd/statsd/events","assignees_url":"https://api.github.com/repos/go-statsd/statsd/assignees{/user}","branches_url":"https://api.github.com/repos/go-statsd/statsd/branches{/branch}","tags_url":"https://api.github.com/repos/go-statsd/statsd/tags","blobs_url":"https://api.github.com/repos/go-statsd/statsd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/go-statsd/statsd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/go-statsd/statsd/git/refs{/sha}","trees_url":"https://api.github.com/repos/go-statsd/statsd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/go-statsd/statsd/statuses/{sha}","languages_url":"https://api.github.com/repos/go-statsd/statsd/languages","stargazers_url":"https://api.github.com/repos/go-statsd/statsd/stargazers","contributors_url":"https://api.github.com/repos/go-statsd/statsd/contributors","subscribers_url":"https://api.github.com/repos/go-statsd/statsd/subscribers","subscription_url":"https://api.github.com/repos/go-statsd/statsd/subscription","commits_url":"https://api.github.com/repos/go-statsd/statsd/commits{/sha}","git_commits_url":"https://api.github.com/repos/go-statsd/statsd/git/commits{/sha}","comments_url":"https://api.github.com/repos/go-statsd/statsd/comments{/number}","issue_comment_url":"https://api.github.com/repos/go-statsd/statsd/issues/comments{/number}","contents_url":"https://api.github.com/repos/go-statsd/statsd/contents/{+path}","compare_url":"https://api.github.com/repos/go-statsd/statsd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/go-statsd/statsd/merges","archive_url":"https://api.github.com/repos/go-statsd/statsd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/go-statsd/statsd/downloads","issues_url":"https://api.github.com/repos/go-statsd/statsd/issues{/number}","pulls_url":"https://api.github.com/repos/go-statsd/statsd/pulls{/number}","milestones_url":"https://api.github.com/repos/go-statsd/statsd/milestones{/number}","notifications_url":"https://api.github.com/repos/go-statsd/statsd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/go-statsd/statsd/labels{/name}","releases_url":"https://api.github.com/repos/go-statsd/statsd/releases{/id}","created_at":"2015-02-12T01:25:02Z","updated_at":"2015-02-20T17:05:53Z","pushed_at":"2015-02-20T17:05:51Z","git_url":"git://github.com/go-statsd/statsd.git","ssh_url":"git@github.com:go-statsd/statsd.git","clone_url":"https://github.com/go-statsd/statsd.git","svn_url":"https://github.com/go-statsd/statsd","homepage":"http://godoc.org/gopkg.in/statsd.v1","size":168,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/go-statsd/statsd/pulls/1"},"html":{"href":"https://github.com/go-statsd/statsd/pull/1"},"issue":{"href":"https://api.github.com/repos/go-statsd/statsd/issues/1"},"comments":{"href":"https://api.github.com/repos/go-statsd/statsd/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/go-statsd/statsd/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/go-statsd/statsd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/go-statsd/statsd/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/go-statsd/statsd/statuses/2a0dd4543eea14f4ab48da298a0718c43700b2ca"}}}}