{"action":"created","issue":{"url":"https://api.github.com/repos/pseudomuto/protokit/issues/2","repository_url":"https://api.github.com/repos/pseudomuto/protokit","labels_url":"https://api.github.com/repos/pseudomuto/protokit/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/pseudomuto/protokit/issues/2/comments","events_url":"https://api.github.com/repos/pseudomuto/protokit/issues/2/events","html_url":"https://github.com/pseudomuto/protokit/pull/2","id":351273108,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA4OTExNTA0","number":2,"title":"Add support for extracting extensions from options","user":{"login":"htdvisser","id":181308,"node_id":"MDQ6VXNlcjE4MTMwOA==","avatar_url":"https://avatars3.githubusercontent.com/u/181308?v=4","gravatar_id":"","url":"https://api.github.com/users/htdvisser","html_url":"https://github.com/htdvisser","followers_url":"https://api.github.com/users/htdvisser/followers","following_url":"https://api.github.com/users/htdvisser/following{/other_user}","gists_url":"https://api.github.com/users/htdvisser/gists{/gist_id}","starred_url":"https://api.github.com/users/htdvisser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/htdvisser/subscriptions","organizations_url":"https://api.github.com/users/htdvisser/orgs","repos_url":"https://api.github.com/users/htdvisser/repos","events_url":"https://api.github.com/users/htdvisser/events{/privacy}","received_events_url":"https://api.github.com/users/htdvisser/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-16T16:11:46Z","updated_at":"2018-08-17T07:49:34Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/pseudomuto/protokit/pulls/2","html_url":"https://github.com/pseudomuto/protokit/pull/2","diff_url":"https://github.com/pseudomuto/protokit/pull/2.diff","patch_url":"https://github.com/pseudomuto/protokit/pull/2.patch"},"body":"ping @pseudomuto\r\n\r\n### What is Changing?\r\n\r\n<!-- _Make sure you spell out in as much detail as necessary what will happen to which systems when your PR is merged, \r\nwhat are the expected changes._ -->\r\n\r\nThis Pull Request adds support for extension-defined options for messages, fields, methods, etc. It's the first step in resolving https://github.com/pseudomuto/protoc-gen-doc/issues/202 and https://github.com/pseudomuto/protoc-gen-doc/issues/233. The use case is an RPC service with custom options, such as the `(google.api.http)` MethodOption in the following example:\r\n\r\n```proto\r\nimport \"google/api/annotations.proto\";\r\n\r\nservice Demo {\r\n  rpc Unary (Foo) returns (Bar) {\r\n    option (google.api.http) = {\r\n      post: \"/unary\"\r\n    };\r\n  }\r\n}\r\n```\r\n\r\nand the `(validator.field)` FieldOption in this one:\r\n\r\n```proto\r\nimport \"github.com/mwitkow/go-proto-validators/validator.proto\";\r\n\r\nmessage Foo {\r\n  int32 percentage = 1 [(validator.field) = {int_gte: 0, int_lte: 100}];\r\n}\r\n```\r\n\r\n### How is it Changing?\r\n\r\n<!-- _Include any relevant implementation details, mimize surprises for the reviewers in this section, if you had to take some \r\nunorthodox approaches (read hacks), explain why here._ -->\r\n\r\nI can imagine we wouldn't make everyone happy by importing all possible extensions that are out there, so plugins will have to register the ones they use to protokit by importing the packages that define the extensions:\r\n\r\n```go\r\nimport _ \"google.golang.org/genproto/googleapis/api/annotations\"\r\nimport _ \"github.com/mwitkow/go-proto-validators\"\r\n```\r\n\r\nThis works because the generated `.pb.go` files in those packages contain something like:\r\n\r\n```go\r\nfunc init() {\r\n\tproto.RegisterExtension(E_Http)\r\n}\r\n```\r\n\r\nand we simply range over the registered extensions to match them with the ones in the options.\r\n\r\n### What Could Go Wrong?\r\n\r\n<!-- _How has this change been tested? In your opinion what is the risk, if any, of merging these changes._ -->\r\n\r\nNot much. The `setExtensions` func is only called if there are options to begin with, it only looks at extensions that are registered for the given options, and skips anything that errors. I also added a test case to make sure this work as intended. "},"comment":{"url":"https://api.github.com/repos/pseudomuto/protokit/issues/comments/413786833","html_url":"https://github.com/pseudomuto/protokit/pull/2#issuecomment-413786833","issue_url":"https://api.github.com/repos/pseudomuto/protokit/issues/2","id":413786833,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzc4NjgzMw==","user":{"login":"htdvisser","id":181308,"node_id":"MDQ6VXNlcjE4MTMwOA==","avatar_url":"https://avatars3.githubusercontent.com/u/181308?v=4","gravatar_id":"","url":"https://api.github.com/users/htdvisser","html_url":"https://github.com/htdvisser","followers_url":"https://api.github.com/users/htdvisser/followers","following_url":"https://api.github.com/users/htdvisser/following{/other_user}","gists_url":"https://api.github.com/users/htdvisser/gists{/gist_id}","starred_url":"https://api.github.com/users/htdvisser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/htdvisser/subscriptions","organizations_url":"https://api.github.com/users/htdvisser/orgs","repos_url":"https://api.github.com/users/htdvisser/repos","events_url":"https://api.github.com/users/htdvisser/events{/privacy}","received_events_url":"https://api.github.com/users/htdvisser/received_events","type":"User","site_admin":false},"created_at":"2018-08-17T07:49:34Z","updated_at":"2018-08-17T07:49:34Z","author_association":"NONE","body":"Please wait with review/merge until I've added some more test coverage to make codecov happy"}}
{"actor":{"display_login":"htdvisser"}}