{"action":"created","comment":{"url":"https://api.github.com/repos/go-kit/kit/pulls/comments/41735744","id":41735744,"diff_hunk":"@@ -0,0 +1,175 @@\n+package consul\n+\n+import (\n+\t\"fmt\"\n+\n+\t\"github.com/go-kit/kit/endpoint\"\n+\t\"github.com/go-kit/kit/loadbalancer\"\n+\t\"github.com/go-kit/kit/log\"\n+\tconsul \"github.com/hashicorp/consul/api\"\n+)\n+\n+const defaultIndex = 0\n+\n+// Publisher yields endpoints for the given service filtered by tags.\n+type Publisher struct {\n+\tcache      *loadbalancer.EndpointCache\n+\tclient     Client\n+\tlogger     log.Logger\n+\tservice    string\n+\ttags       []string\n+\tendpointsc chan []endpoint.Endpoint\n+\tquitc      chan struct{}\n+}\n+\n+// NewPublisher returns a Consul publisher which returns Endpoints for the\n+// requested service. It only returns instances for which all of the passed\n+// tags are present.\n+func NewPublisher(\n+\tclient Client,\n+\tfactory loadbalancer.Factory,\n+\tlogger log.Logger,\n+\tservice string,\n+\ttags ...string,\n+) (*Publisher, error) {\n+\tlogger = log.NewContext(logger).With(\"component\", \"Consul Publisher\")\n+\n+\tp := &Publisher{\n+\t\tcache:   loadbalancer.NewEndpointCache(factory, logger),\n+\t\tclient:  client,\n+\t\tlogger:  logger,\n+\t\tservice: service,\n+\t\ttags:    tags,\n+\t\tquitc:   make(chan struct{}),\n+\t}\n+\n+\tis, index, err := p.getInstances(defaultIndex)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tp.cache.Replace(is)\n+\n+\tgo p.loop(index)\n+\n+\treturn p, nil\n+}\n+\n+// Endpoints implements the Publisher interface.\n+func (p *Publisher) Endpoints() ([]endpoint.Endpoint, error) {\n+\treturn p.cache.Endpoints(), nil\n+}\n+\n+// Stop terminates the publisher.\n+func (p *Publisher) Stop() {\n+\tclose(p.quitc)\n+}\n+\n+func (p *Publisher) loop(\n+\tlastIndex uint64,\n+) {\n+\tvar (\n+\t\terrc = make(chan error)\n+\t\tresc = make(chan response)\n+\t)\n+\n+\tfor {\n+\t\tgo func() {","path":"loadbalancer/consul/publisher.go","position":77,"original_position":77,"commit_id":"db403323349f19da085cfc86c61d57ce687fdf51","original_commit_id":"db403323349f19da085cfc86c61d57ce687fdf51","user":{"login":"tsenart","id":67471,"avatar_url":"https://avatars.githubusercontent.com/u/67471?v=3","gravatar_id":"","url":"https://api.github.com/users/tsenart","html_url":"https://github.com/tsenart","followers_url":"https://api.github.com/users/tsenart/followers","following_url":"https://api.github.com/users/tsenart/following{/other_user}","gists_url":"https://api.github.com/users/tsenart/gists{/gist_id}","starred_url":"https://api.github.com/users/tsenart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsenart/subscriptions","organizations_url":"https://api.github.com/users/tsenart/orgs","repos_url":"https://api.github.com/users/tsenart/repos","events_url":"https://api.github.com/users/tsenart/events{/privacy}","received_events_url":"https://api.github.com/users/tsenart/received_events","type":"User","site_admin":false},"body":"I don't see a need for the use of concurrency here. Why do we need the go-routine? The only thing you need so select on here is the `s.quitc` channel as far as I understand it.","created_at":"2015-10-12T08:56:47Z","updated_at":"2015-10-12T08:56:47Z","html_url":"https://github.com/go-kit/kit/pull/100#discussion_r41735744","pull_request_url":"https://api.github.com/repos/go-kit/kit/pulls/100","_links":{"self":{"href":"https://api.github.com/repos/go-kit/kit/pulls/comments/41735744"},"html":{"href":"https://github.com/go-kit/kit/pull/100#discussion_r41735744"},"pull_request":{"href":"https://api.github.com/repos/go-kit/kit/pulls/100"}}},"pull_request":{"url":"https://api.github.com/repos/go-kit/kit/pulls/100","id":42565118,"html_url":"https://github.com/go-kit/kit/pull/100","diff_url":"https://github.com/go-kit/kit/pull/100.diff","patch_url":"https://github.com/go-kit/kit/pull/100.patch","issue_url":"https://api.github.com/repos/go-kit/kit/issues/100","number":100,"state":"open","locked":false,"title":"Add Consul publisher","user":{"login":"xla","id":1585,"avatar_url":"https://avatars.githubusercontent.com/u/1585?v=3","gravatar_id":"","url":"https://api.github.com/users/xla","html_url":"https://github.com/xla","followers_url":"https://api.github.com/users/xla/followers","following_url":"https://api.github.com/users/xla/following{/other_user}","gists_url":"https://api.github.com/users/xla/gists{/gist_id}","starred_url":"https://api.github.com/users/xla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xla/subscriptions","organizations_url":"https://api.github.com/users/xla/orgs","repos_url":"https://api.github.com/users/xla/repos","events_url":"https://api.github.com/users/xla/events{/privacy}","received_events_url":"https://api.github.com/users/xla/received_events","type":"User","site_admin":false},"body":"**open questions**\r\n\r\n- [x] Is it allowed to return stale endpoints?\r\n- [x] Are publishers expected to return `ip:port` or are `hostnames` equally valid?\r\n- [x] Does it suffice to only be able to filter by one tag?\r\n\r\n**todos**\r\n\r\n- [x] only emit endpoints when different\r\n- [ ] documentation\r\n- [ ] example\r\n- [x] tests\r\n\r\n***\r\n*The commits in this branch will be cleaned up in time and likely stashed into a single coherent change-set.*","created_at":"2015-08-17T08:39:35Z","updated_at":"2015-10-12T08:56:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f77cc1a4ae8c46252ac372fe6829253cbffd7bb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/go-kit/kit/pulls/100/commits","review_comments_url":"https://api.github.com/repos/go-kit/kit/pulls/100/comments","review_comment_url":"https://api.github.com/repos/go-kit/kit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/go-kit/kit/issues/100/comments","statuses_url":"https://api.github.com/repos/go-kit/kit/statuses/db403323349f19da085cfc86c61d57ce687fdf51","head":{"label":"xla:consul-publisher","ref":"consul-publisher","sha":"db403323349f19da085cfc86c61d57ce687fdf51","user":{"login":"xla","id":1585,"avatar_url":"https://avatars.githubusercontent.com/u/1585?v=3","gravatar_id":"","url":"https://api.github.com/users/xla","html_url":"https://github.com/xla","followers_url":"https://api.github.com/users/xla/followers","following_url":"https://api.github.com/users/xla/following{/other_user}","gists_url":"https://api.github.com/users/xla/gists{/gist_id}","starred_url":"https://api.github.com/users/xla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xla/subscriptions","organizations_url":"https://api.github.com/users/xla/orgs","repos_url":"https://api.github.com/users/xla/repos","events_url":"https://api.github.com/users/xla/events{/privacy}","received_events_url":"https://api.github.com/users/xla/received_events","type":"User","site_admin":false},"repo":{"id":40816116,"name":"kit","full_name":"xla/kit","owner":{"login":"xla","id":1585,"avatar_url":"https://avatars.githubusercontent.com/u/1585?v=3","gravatar_id":"","url":"https://api.github.com/users/xla","html_url":"https://github.com/xla","followers_url":"https://api.github.com/users/xla/followers","following_url":"https://api.github.com/users/xla/following{/other_user}","gists_url":"https://api.github.com/users/xla/gists{/gist_id}","starred_url":"https://api.github.com/users/xla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xla/subscriptions","organizations_url":"https://api.github.com/users/xla/orgs","repos_url":"https://api.github.com/users/xla/repos","events_url":"https://api.github.com/users/xla/events{/privacy}","received_events_url":"https://api.github.com/users/xla/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xla/kit","description":"A Go toolkit for microservices.","fork":true,"url":"https://api.github.com/repos/xla/kit","forks_url":"https://api.github.com/repos/xla/kit/forks","keys_url":"https://api.github.com/repos/xla/kit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xla/kit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xla/kit/teams","hooks_url":"https://api.github.com/repos/xla/kit/hooks","issue_events_url":"https://api.github.com/repos/xla/kit/issues/events{/number}","events_url":"https://api.github.com/repos/xla/kit/events","assignees_url":"https://api.github.com/repos/xla/kit/assignees{/user}","branches_url":"https://api.github.com/repos/xla/kit/branches{/branch}","tags_url":"https://api.github.com/repos/xla/kit/tags","blobs_url":"https://api.github.com/repos/xla/kit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xla/kit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xla/kit/git/refs{/sha}","trees_url":"https://api.github.com/repos/xla/kit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xla/kit/statuses/{sha}","languages_url":"https://api.github.com/repos/xla/kit/languages","stargazers_url":"https://api.github.com/repos/xla/kit/stargazers","contributors_url":"https://api.github.com/repos/xla/kit/contributors","subscribers_url":"https://api.github.com/repos/xla/kit/subscribers","subscription_url":"https://api.github.com/repos/xla/kit/subscription","commits_url":"https://api.github.com/repos/xla/kit/commits{/sha}","git_commits_url":"https://api.github.com/repos/xla/kit/git/commits{/sha}","comments_url":"https://api.github.com/repos/xla/kit/comments{/number}","issue_comment_url":"https://api.github.com/repos/xla/kit/issues/comments{/number}","contents_url":"https://api.github.com/repos/xla/kit/contents/{+path}","compare_url":"https://api.github.com/repos/xla/kit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xla/kit/merges","archive_url":"https://api.github.com/repos/xla/kit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xla/kit/downloads","issues_url":"https://api.github.com/repos/xla/kit/issues{/number}","pulls_url":"https://api.github.com/repos/xla/kit/pulls{/number}","milestones_url":"https://api.github.com/repos/xla/kit/milestones{/number}","notifications_url":"https://api.github.com/repos/xla/kit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xla/kit/labels{/name}","releases_url":"https://api.github.com/repos/xla/kit/releases{/id}","created_at":"2015-08-16T12:29:22Z","updated_at":"2015-08-16T12:29:22Z","pushed_at":"2015-10-10T14:48:51Z","git_url":"git://github.com/xla/kit.git","ssh_url":"git@github.com:xla/kit.git","clone_url":"https://github.com/xla/kit.git","svn_url":"https://github.com/xla/kit","homepage":"http://gokit.io","size":489,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":0,"forks":2,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"go-kit:master","ref":"master","sha":"144a8c62fa80f4c76e40c55f965c21ba153ebdb0","user":{"login":"go-kit","id":10981023,"avatar_url":"https://avatars.githubusercontent.com/u/10981023?v=3","gravatar_id":"","url":"https://api.github.com/users/go-kit","html_url":"https://github.com/go-kit","followers_url":"https://api.github.com/users/go-kit/followers","following_url":"https://api.github.com/users/go-kit/following{/other_user}","gists_url":"https://api.github.com/users/go-kit/gists{/gist_id}","starred_url":"https://api.github.com/users/go-kit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-kit/subscriptions","organizations_url":"https://api.github.com/users/go-kit/orgs","repos_url":"https://api.github.com/users/go-kit/repos","events_url":"https://api.github.com/users/go-kit/events{/privacy}","received_events_url":"https://api.github.com/users/go-kit/received_events","type":"Organization","site_admin":false},"repo":{"id":30215630,"name":"kit","full_name":"go-kit/kit","owner":{"login":"go-kit","id":10981023,"avatar_url":"https://avatars.githubusercontent.com/u/10981023?v=3","gravatar_id":"","url":"https://api.github.com/users/go-kit","html_url":"https://github.com/go-kit","followers_url":"https://api.github.com/users/go-kit/followers","following_url":"https://api.github.com/users/go-kit/following{/other_user}","gists_url":"https://api.github.com/users/go-kit/gists{/gist_id}","starred_url":"https://api.github.com/users/go-kit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-kit/subscriptions","organizations_url":"https://api.github.com/users/go-kit/orgs","repos_url":"https://api.github.com/users/go-kit/repos","events_url":"https://api.github.com/users/go-kit/events{/privacy}","received_events_url":"https://api.github.com/users/go-kit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/go-kit/kit","description":"A standard library for microservices.","fork":false,"url":"https://api.github.com/repos/go-kit/kit","forks_url":"https://api.github.com/repos/go-kit/kit/forks","keys_url":"https://api.github.com/repos/go-kit/kit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/go-kit/kit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/go-kit/kit/teams","hooks_url":"https://api.github.com/repos/go-kit/kit/hooks","issue_events_url":"https://api.github.com/repos/go-kit/kit/issues/events{/number}","events_url":"https://api.github.com/repos/go-kit/kit/events","assignees_url":"https://api.github.com/repos/go-kit/kit/assignees{/user}","branches_url":"https://api.github.com/repos/go-kit/kit/branches{/branch}","tags_url":"https://api.github.com/repos/go-kit/kit/tags","blobs_url":"https://api.github.com/repos/go-kit/kit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/go-kit/kit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/go-kit/kit/git/refs{/sha}","trees_url":"https://api.github.com/repos/go-kit/kit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/go-kit/kit/statuses/{sha}","languages_url":"https://api.github.com/repos/go-kit/kit/languages","stargazers_url":"https://api.github.com/repos/go-kit/kit/stargazers","contributors_url":"https://api.github.com/repos/go-kit/kit/contributors","subscribers_url":"https://api.github.com/repos/go-kit/kit/subscribers","subscription_url":"https://api.github.com/repos/go-kit/kit/subscription","commits_url":"https://api.github.com/repos/go-kit/kit/commits{/sha}","git_commits_url":"https://api.github.com/repos/go-kit/kit/git/commits{/sha}","comments_url":"https://api.github.com/repos/go-kit/kit/comments{/number}","issue_comment_url":"https://api.github.com/repos/go-kit/kit/issues/comments{/number}","contents_url":"https://api.github.com/repos/go-kit/kit/contents/{+path}","compare_url":"https://api.github.com/repos/go-kit/kit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/go-kit/kit/merges","archive_url":"https://api.github.com/repos/go-kit/kit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/go-kit/kit/downloads","issues_url":"https://api.github.com/repos/go-kit/kit/issues{/number}","pulls_url":"https://api.github.com/repos/go-kit/kit/pulls{/number}","milestones_url":"https://api.github.com/repos/go-kit/kit/milestones{/number}","notifications_url":"https://api.github.com/repos/go-kit/kit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/go-kit/kit/labels{/name}","releases_url":"https://api.github.com/repos/go-kit/kit/releases{/id}","created_at":"2015-02-03T00:01:19Z","updated_at":"2015-10-12T03:51:30Z","pushed_at":"2015-10-12T07:40:48Z","git_url":"git://github.com/go-kit/kit.git","ssh_url":"git@github.com:go-kit/kit.git","clone_url":"https://github.com/go-kit/kit.git","svn_url":"https://github.com/go-kit/kit","homepage":"http://gokit.io","size":8663,"stargazers_count":2268,"watchers_count":2268,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":154,"mirror_url":null,"open_issues_count":17,"forks":154,"open_issues":17,"watchers":2268,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/go-kit/kit/pulls/100"},"html":{"href":"https://github.com/go-kit/kit/pull/100"},"issue":{"href":"https://api.github.com/repos/go-kit/kit/issues/100"},"comments":{"href":"https://api.github.com/repos/go-kit/kit/issues/100/comments"},"review_comments":{"href":"https://api.github.com/repos/go-kit/kit/pulls/100/comments"},"review_comment":{"href":"https://api.github.com/repos/go-kit/kit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/go-kit/kit/pulls/100/commits"},"statuses":{"href":"https://api.github.com/repos/go-kit/kit/statuses/db403323349f19da085cfc86c61d57ce687fdf51"}}}}