{"action":"created","comment":{"url":"https://api.github.com/repos/eleven-labs/codelabs/pulls/comments/187054607","pull_request_review_id":118748897,"id":187054607,"diff_hunk":"@@ -0,0 +1,150 @@\n+### Ajout d'un proxy REST et d'une doc Swagger\n+\n+Nous allons maintenant voir comment exposer un service gPRC comme une API REST.\n+Puisqu'un serveur gRPC n'est pas disponible pour le web, l'une des solutions est de créer un autre service qui va exposer une route REST et appeler le service gRPC.\n+\n+[grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) est un plugin protoc pour auto-générer un proxy HTTP via de la conf dans le fichier protobuf.\n+```\n+    HTTP request\n+        |\n+        v\n+ --------------                   ---------------\n+|  HTTP Proxy  |   json/proto    |  gRPC Server  |\n+|   on :8001   | ------------->  |   on :4000    |\n+ --------------  <-------------   ---------------\n+```\n+Nous allons commencer par installer les plugins `grpc-gateway` et `swagger` pour protoc.\n+```bash\n+go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway\n+go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger\n+```\n+\n+Nous allons modifier le fichier `proto/translator.proto`  pour ajouter les directives de génération du proxy HTTP.\n+Pour ce faire, il faut ajouter des options à notre endpoint RPC.\n+```proto\n+option (google.api.http) = {\n+      post: \"/v1/translate\"\n+      body: \"*\"\n+};\n+```\n+Ici, on définit une route `/v1/translate` avec le verbe POST.\n+\n+Ce qui nous donne :\n+```proto\n+syntax = \"proto3\";\n+\n+package proto;\n+\n+import \"google/api/annotations.proto\";\n+\n+enum Language {\n+    en = 0;\n+    fr = 1;\n+}\n+\n+message TranslateRequest {\n+    string text = 1;\n+    Language language = 2;\n+}\n+\n+message TranslateResponse {\n+    string text = 1;\n+}\n+\n+service Translator {\n+    rpc Translate(TranslateRequest) returns (TranslateResponse) {\n+        option (google.api.http) = {\n+          post: \"/v1/translate\"\n+          body: \"*\"\n+        };\n+    }\n+}\n+```\n+\n+Nous allons maintenant modifer le fichier `prototool.yaml` pour générer le proxy et le json de Swagger.\n+```yaml\n+# prototool.yaml\n+protoc_includes:  \n+  - ../../src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis  \n+  \n+gen:  \n+ go_options: import_path: translator-service/  \n+  \n+  plugins:  \n+  - name: go  \n+      type: go  \n+      flags: plugins=grpc  \n+      output: .  \n+    - name: grpc-gateway  \n+      type: go  \n+      output: .  \n+    - name: swagger  \n+      type: go  \n+      output: swagger/.\n+```\n+Nous pouvons maintenant générer les fichiers Go.\n+```bash\n+prototool gen\n+```\n+Nous allons maintenant utiliser ce proxy qui a été générée et créer un fichier `proxy.go`.\n+Il suffit de lancer le serveur gRPC dans un go-routine et d'exposer le proxy HTTP.\n+```go\n+// proxy.go\n+package main  \n+  \n+import (  \n+\t\"context\"  \n+\t\"net/http\"\n+\t\"github.com/grpc-ecosystem/grpc-gateway/runtime\"\n+\t\"google.golang.org/grpc\"\n+\t\"translator-service/proto\"\n+)  \n+\n+func main() {\n+    lis, err := net.Listen(\"tcp\", \"localhost:4000\")\n+    if err != nil {\n+        log.Fatalf(\"failed to listen: %v\", err)\n+    }\n+    translator := translate.NewGoogleTranslator(os.Getenv(\"TRANSLATION_API_KEY\"))\n+    srv := server.NewTranslatorServer(server.Endpoints{\n+        TranslateEndpoint: server.NewTranslateEndpoint(translator),\n+    })\n+    s := grpc.NewServer()\n+    proto.RegisterTranslatorServer(s, srv)\n+    go s.Serve(lis)\n+\n+\tctx := context.Background()\n+\tctx, cancel := context.WithCancel(ctx)  \n+\tdefer cancel()  \n+\n+\tmux := runtime.NewServeMux()  \n+\topts := []grpc.DialOption{grpc.WithInsecure()}  \n+\tproto.RegisterTranslatorHandlerFromEndpoint(ctx, mux, \"localhost:4000\", opts)  \n+\n+\thttp.ListenAndServe(\":8001\", mux)  ","path":"_posts/codelabs/2018-05-03-microservice-avec-go-et-grpc/step6.md","position":124,"original_position":124,"commit_id":"bf791c4f189d93ddbfd667097eb82c69169406f0","original_commit_id":"bf791c4f189d93ddbfd667097eb82c69169406f0","user":{"login":"snroki","id":3913327,"avatar_url":"https://avatars2.githubusercontent.com/u/3913327?v=4","gravatar_id":"","url":"https://api.github.com/users/snroki","html_url":"https://github.com/snroki","followers_url":"https://api.github.com/users/snroki/followers","following_url":"https://api.github.com/users/snroki/following{/other_user}","gists_url":"https://api.github.com/users/snroki/gists{/gist_id}","starred_url":"https://api.github.com/users/snroki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snroki/subscriptions","organizations_url":"https://api.github.com/users/snroki/orgs","repos_url":"https://api.github.com/users/snroki/repos","events_url":"https://api.github.com/users/snroki/events{/privacy}","received_events_url":"https://api.github.com/users/snroki/received_events","type":"User","site_admin":false},"body":"problème d'indentation sur les lignes 116 à 124 ?","created_at":"2018-05-09T14:15:43Z","updated_at":"2018-05-09T14:18:10Z","html_url":"https://github.com/eleven-labs/codelabs/pull/112#discussion_r187054607","pull_request_url":"https://api.github.com/repos/eleven-labs/codelabs/pulls/112","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/eleven-labs/codelabs/pulls/comments/187054607"},"html":{"href":"https://github.com/eleven-labs/codelabs/pull/112#discussion_r187054607"},"pull_request":{"href":"https://api.github.com/repos/eleven-labs/codelabs/pulls/112"}}},"pull_request":{"url":"https://api.github.com/repos/eleven-labs/codelabs/pulls/112","id":184568224,"html_url":"https://github.com/eleven-labs/codelabs/pull/112","diff_url":"https://github.com/eleven-labs/codelabs/pull/112.diff","patch_url":"https://github.com/eleven-labs/codelabs/pull/112.patch","issue_url":"https://api.github.com/repos/eleven-labs/codelabs/issues/112","number":112,"state":"open","locked":false,"title":"add tuto microservice-avec-go-et-grpc","user":{"login":"qneyrat","id":12870790,"avatar_url":"https://avatars1.githubusercontent.com/u/12870790?v=4","gravatar_id":"","url":"https://api.github.com/users/qneyrat","html_url":"https://github.com/qneyrat","followers_url":"https://api.github.com/users/qneyrat/followers","following_url":"https://api.github.com/users/qneyrat/following{/other_user}","gists_url":"https://api.github.com/users/qneyrat/gists{/gist_id}","starred_url":"https://api.github.com/users/qneyrat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qneyrat/subscriptions","organizations_url":"https://api.github.com/users/qneyrat/orgs","repos_url":"https://api.github.com/users/qneyrat/repos","events_url":"https://api.github.com/users/qneyrat/events{/privacy}","received_events_url":"https://api.github.com/users/qneyrat/received_events","type":"User","site_admin":false},"body":"TODO:\r\n- [ ] Change `nous allons ...`\r\n- [ ] Update date","created_at":"2018-04-27T09:23:03Z","updated_at":"2018-05-09T14:18:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dbb86a7578ccff0fb118e9c132a3aebd5cff740d","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":637556785,"url":"https://api.github.com/repos/eleven-labs/codelabs/labels/RFR","name":"RFR","color":"006b75","default":false},{"id":831262525,"url":"https://api.github.com/repos/eleven-labs/codelabs/labels/publication","name":"publication","color":"d93f0b","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/eleven-labs/codelabs/pulls/112/commits","review_comments_url":"https://api.github.com/repos/eleven-labs/codelabs/pulls/112/comments","review_comment_url":"https://api.github.com/repos/eleven-labs/codelabs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/eleven-labs/codelabs/issues/112/comments","statuses_url":"https://api.github.com/repos/eleven-labs/codelabs/statuses/bf791c4f189d93ddbfd667097eb82c69169406f0","head":{"label":"eleven-labs:microservice-avec-go-et-grpc","ref":"microservice-avec-go-et-grpc","sha":"bf791c4f189d93ddbfd667097eb82c69169406f0","user":{"login":"eleven-labs","id":5772631,"avatar_url":"https://avatars0.githubusercontent.com/u/5772631?v=4","gravatar_id":"","url":"https://api.github.com/users/eleven-labs","html_url":"https://github.com/eleven-labs","followers_url":"https://api.github.com/users/eleven-labs/followers","following_url":"https://api.github.com/users/eleven-labs/following{/other_user}","gists_url":"https://api.github.com/users/eleven-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/eleven-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eleven-labs/subscriptions","organizations_url":"https://api.github.com/users/eleven-labs/orgs","repos_url":"https://api.github.com/users/eleven-labs/repos","events_url":"https://api.github.com/users/eleven-labs/events{/privacy}","received_events_url":"https://api.github.com/users/eleven-labs/received_events","type":"Organization","site_admin":false},"repo":{"id":95873034,"name":"codelabs","full_name":"eleven-labs/codelabs","owner":{"login":"eleven-labs","id":5772631,"avatar_url":"https://avatars0.githubusercontent.com/u/5772631?v=4","gravatar_id":"","url":"https://api.github.com/users/eleven-labs","html_url":"https://github.com/eleven-labs","followers_url":"https://api.github.com/users/eleven-labs/followers","following_url":"https://api.github.com/users/eleven-labs/following{/other_user}","gists_url":"https://api.github.com/users/eleven-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/eleven-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eleven-labs/subscriptions","organizations_url":"https://api.github.com/users/eleven-labs/orgs","repos_url":"https://api.github.com/users/eleven-labs/repos","events_url":"https://api.github.com/users/eleven-labs/events{/privacy}","received_events_url":"https://api.github.com/users/eleven-labs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/eleven-labs/codelabs","description":null,"fork":false,"url":"https://api.github.com/repos/eleven-labs/codelabs","forks_url":"https://api.github.com/repos/eleven-labs/codelabs/forks","keys_url":"https://api.github.com/repos/eleven-labs/codelabs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eleven-labs/codelabs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eleven-labs/codelabs/teams","hooks_url":"https://api.github.com/repos/eleven-labs/codelabs/hooks","issue_events_url":"https://api.github.com/repos/eleven-labs/codelabs/issues/events{/number}","events_url":"https://api.github.com/repos/eleven-labs/codelabs/events","assignees_url":"https://api.github.com/repos/eleven-labs/codelabs/assignees{/user}","branches_url":"https://api.github.com/repos/eleven-labs/codelabs/branches{/branch}","tags_url":"https://api.github.com/repos/eleven-labs/codelabs/tags","blobs_url":"https://api.github.com/repos/eleven-labs/codelabs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eleven-labs/codelabs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eleven-labs/codelabs/git/refs{/sha}","trees_url":"https://api.github.com/repos/eleven-labs/codelabs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eleven-labs/codelabs/statuses/{sha}","languages_url":"https://api.github.com/repos/eleven-labs/codelabs/languages","stargazers_url":"https://api.github.com/repos/eleven-labs/codelabs/stargazers","contributors_url":"https://api.github.com/repos/eleven-labs/codelabs/contributors","subscribers_url":"https://api.github.com/repos/eleven-labs/codelabs/subscribers","subscription_url":"https://api.github.com/repos/eleven-labs/codelabs/subscription","commits_url":"https://api.github.com/repos/eleven-labs/codelabs/commits{/sha}","git_commits_url":"https://api.github.com/repos/eleven-labs/codelabs/git/commits{/sha}","comments_url":"https://api.github.com/repos/eleven-labs/codelabs/comments{/number}","issue_comment_url":"https://api.github.com/repos/eleven-labs/codelabs/issues/comments{/number}","contents_url":"https://api.github.com/repos/eleven-labs/codelabs/contents/{+path}","compare_url":"https://api.github.com/repos/eleven-labs/codelabs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eleven-labs/codelabs/merges","archive_url":"https://api.github.com/repos/eleven-labs/codelabs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eleven-labs/codelabs/downloads","issues_url":"https://api.github.com/repos/eleven-labs/codelabs/issues{/number}","pulls_url":"https://api.github.com/repos/eleven-labs/codelabs/pulls{/number}","milestones_url":"https://api.github.com/repos/eleven-labs/codelabs/milestones{/number}","notifications_url":"https://api.github.com/repos/eleven-labs/codelabs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eleven-labs/codelabs/labels{/name}","releases_url":"https://api.github.com/repos/eleven-labs/codelabs/releases{/id}","deployments_url":"https://api.github.com/repos/eleven-labs/codelabs/deployments","created_at":"2017-06-30T09:32:41Z","updated_at":"2018-04-30T12:49:38Z","pushed_at":"2018-05-09T13:53:36Z","git_url":"git://github.com/eleven-labs/codelabs.git","ssh_url":"git@github.com:eleven-labs/codelabs.git","clone_url":"https://github.com/eleven-labs/codelabs.git","svn_url":"https://github.com/eleven-labs/codelabs","homepage":null,"size":21114,"stargazers_count":9,"watchers_count":9,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":30,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":2,"open_issues":30,"watchers":9,"default_branch":"master"}},"base":{"label":"eleven-labs:master","ref":"master","sha":"93709a001e626eefed953b7591478e7915f67d5b","user":{"login":"eleven-labs","id":5772631,"avatar_url":"https://avatars0.githubusercontent.com/u/5772631?v=4","gravatar_id":"","url":"https://api.github.com/users/eleven-labs","html_url":"https://github.com/eleven-labs","followers_url":"https://api.github.com/users/eleven-labs/followers","following_url":"https://api.github.com/users/eleven-labs/following{/other_user}","gists_url":"https://api.github.com/users/eleven-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/eleven-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eleven-labs/subscriptions","organizations_url":"https://api.github.com/users/eleven-labs/orgs","repos_url":"https://api.github.com/users/eleven-labs/repos","events_url":"https://api.github.com/users/eleven-labs/events{/privacy}","received_events_url":"https://api.github.com/users/eleven-labs/received_events","type":"Organization","site_admin":false},"repo":{"id":95873034,"name":"codelabs","full_name":"eleven-labs/codelabs","owner":{"login":"eleven-labs","id":5772631,"avatar_url":"https://avatars0.githubusercontent.com/u/5772631?v=4","gravatar_id":"","url":"https://api.github.com/users/eleven-labs","html_url":"https://github.com/eleven-labs","followers_url":"https://api.github.com/users/eleven-labs/followers","following_url":"https://api.github.com/users/eleven-labs/following{/other_user}","gists_url":"https://api.github.com/users/eleven-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/eleven-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eleven-labs/subscriptions","organizations_url":"https://api.github.com/users/eleven-labs/orgs","repos_url":"https://api.github.com/users/eleven-labs/repos","events_url":"https://api.github.com/users/eleven-labs/events{/privacy}","received_events_url":"https://api.github.com/users/eleven-labs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/eleven-labs/codelabs","description":null,"fork":false,"url":"https://api.github.com/repos/eleven-labs/codelabs","forks_url":"https://api.github.com/repos/eleven-labs/codelabs/forks","keys_url":"https://api.github.com/repos/eleven-labs/codelabs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eleven-labs/codelabs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eleven-labs/codelabs/teams","hooks_url":"https://api.github.com/repos/eleven-labs/codelabs/hooks","issue_events_url":"https://api.github.com/repos/eleven-labs/codelabs/issues/events{/number}","events_url":"https://api.github.com/repos/eleven-labs/codelabs/events","assignees_url":"https://api.github.com/repos/eleven-labs/codelabs/assignees{/user}","branches_url":"https://api.github.com/repos/eleven-labs/codelabs/branches{/branch}","tags_url":"https://api.github.com/repos/eleven-labs/codelabs/tags","blobs_url":"https://api.github.com/repos/eleven-labs/codelabs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eleven-labs/codelabs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eleven-labs/codelabs/git/refs{/sha}","trees_url":"https://api.github.com/repos/eleven-labs/codelabs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eleven-labs/codelabs/statuses/{sha}","languages_url":"https://api.github.com/repos/eleven-labs/codelabs/languages","stargazers_url":"https://api.github.com/repos/eleven-labs/codelabs/stargazers","contributors_url":"https://api.github.com/repos/eleven-labs/codelabs/contributors","subscribers_url":"https://api.github.com/repos/eleven-labs/codelabs/subscribers","subscription_url":"https://api.github.com/repos/eleven-labs/codelabs/subscription","commits_url":"https://api.github.com/repos/eleven-labs/codelabs/commits{/sha}","git_commits_url":"https://api.github.com/repos/eleven-labs/codelabs/git/commits{/sha}","comments_url":"https://api.github.com/repos/eleven-labs/codelabs/comments{/number}","issue_comment_url":"https://api.github.com/repos/eleven-labs/codelabs/issues/comments{/number}","contents_url":"https://api.github.com/repos/eleven-labs/codelabs/contents/{+path}","compare_url":"https://api.github.com/repos/eleven-labs/codelabs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eleven-labs/codelabs/merges","archive_url":"https://api.github.com/repos/eleven-labs/codelabs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eleven-labs/codelabs/downloads","issues_url":"https://api.github.com/repos/eleven-labs/codelabs/issues{/number}","pulls_url":"https://api.github.com/repos/eleven-labs/codelabs/pulls{/number}","milestones_url":"https://api.github.com/repos/eleven-labs/codelabs/milestones{/number}","notifications_url":"https://api.github.com/repos/eleven-labs/codelabs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eleven-labs/codelabs/labels{/name}","releases_url":"https://api.github.com/repos/eleven-labs/codelabs/releases{/id}","deployments_url":"https://api.github.com/repos/eleven-labs/codelabs/deployments","created_at":"2017-06-30T09:32:41Z","updated_at":"2018-04-30T12:49:38Z","pushed_at":"2018-05-09T13:53:36Z","git_url":"git://github.com/eleven-labs/codelabs.git","ssh_url":"git@github.com:eleven-labs/codelabs.git","clone_url":"https://github.com/eleven-labs/codelabs.git","svn_url":"https://github.com/eleven-labs/codelabs","homepage":null,"size":21114,"stargazers_count":9,"watchers_count":9,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":30,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":2,"open_issues":30,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/eleven-labs/codelabs/pulls/112"},"html":{"href":"https://github.com/eleven-labs/codelabs/pull/112"},"issue":{"href":"https://api.github.com/repos/eleven-labs/codelabs/issues/112"},"comments":{"href":"https://api.github.com/repos/eleven-labs/codelabs/issues/112/comments"},"review_comments":{"href":"https://api.github.com/repos/eleven-labs/codelabs/pulls/112/comments"},"review_comment":{"href":"https://api.github.com/repos/eleven-labs/codelabs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/eleven-labs/codelabs/pulls/112/commits"},"statuses":{"href":"https://api.github.com/repos/eleven-labs/codelabs/statuses/bf791c4f189d93ddbfd667097eb82c69169406f0"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"snroki"}}