{"id":379009,"date":"2024-06-17T15:00:19","date_gmt":"2024-06-17T15:00:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=379009"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=379009","title":{"rendered":"<span>\u041e\u0431 \u043e\u0434\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 gRPC: HTTP-\u043f\u0440\u043e\u043a\u0441\u0438 pog-server<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/storage1\/f6730132\/df8eba09\/ebb81aff\/33e5ae11.png\" data-src=\"https:\/\/habrastorage.org\/storage1\/f6730132\/df8eba09\/ebb81aff\/33e5ae11.png\"\/><\/figure>\n<p>HTTP-\u043f\u0440\u043e\u043a\u0441\u0438 &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0434\u043b\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0433\u043e IP-\u0430\u0434\u0440\u0435\u0441\u0430.<\/p>\n<p>gRPC &#8212; \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 HTTP\/2-\u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0435 \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u044f\u0437\u044b\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0430\u044f <em>Protocol Buffers<\/em>.<\/p>\n<p>\u042f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b HTTP-\u043f\u0440\u043e\u043a\u0441\u0438 <a href=\"https:\/\/gitverse.ru\/muravjov\/pog-server\" rel=\"noopener noreferrer nofollow\">pog-server<\/a>, \u0432\u044b\u043b\u043e\u0436\u0438\u043b \u0432 Open Source \u0438 \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0435\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u0430\u0439\u0442\u044b \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c gRPC:<\/p>\n<pre><code>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c &lt;=> pog-client &lt;=gRPC=> pog-server &lt;=> \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440 <\/code><\/pre>\n<h3>\u0417\u0430\u0447\u0435\u043c<\/h3>\n<p>\u0412 \u043d\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u042f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u043e\u0434\u043d\u0438\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f \u043a ChatGPT: \u0442\u0430\u043a \u0443 \u043c\u0435\u043d\u044f \u0441\u0442\u0430\u043b\u043e 2 \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0441\u044f Terraform. \u041e\u043d \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u043e\u0434 \u043e\u0434\u043d\u0438\u043c \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code>$ export HTTPS_PROXY=http:\/\/west.catbo.net:18080 $ terraform init <\/code><\/pre>\n<p>; \u043e\u0434\u043d\u0430\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u044d\u0442\u0438\u043c \u044f \u0434\u0435\u043b\u0430\u043b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a Google API, \u0438 \u0442\u043e\u0442 \u0437\u0430\u0431\u0440\u0430\u043a\u043e\u0432\u0430\u043b \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440. \u0422\u0430\u043a \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0438 \u043a\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\u0422\u0430\u043a \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u0439\u0442\u0438 \u0442\u0430\u043a\u043e\u0439 \u043a\u0440\u0438\u0441\u0442\u0430\u043b\u044c\u043d\u043e \u0447\u0438\u0441\u0442\u044b\u0439 IP, \u0447\u0442\u043e\u0431\u044b \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u0431\u044b\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0432\u044b\u0448\u0435 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0443 \u043d\u0430\u0441 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430 <a href=\"https:\/\/console.cloud.google.com\/\" rel=\"noopener noreferrer nofollow\">GCP<\/a>, \u0442\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0441\u0442\u0430\u043b \u0431\u044b \u0441\u0435\u0440\u0432\u0438\u0441 <code>Cloud Run<\/code>, \u0438\u0433\u0440\u0430\u044e\u0449\u0438\u0439 \u0440\u043e\u043b\u044c \u043f\u0440\u043e\u043a\u0441-\u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434. \u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, &#171;let\u2019s make this world a better place&#187;.<\/p>\n<h3>gRPC. \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043e\u043f\u044b\u0442<\/h3>\n<p>\u041d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0431\u044b\u043b \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d gRPC: \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u043d\u043e\u0434\u044b \u0434\u043e edge-\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Protocol Buffers. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c gRPC \u0431\u044b\u043b\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0440\u0430\u0441\u043f\u043e\u0440\u0442\u0430 \u0431\u044b\u043b \u043d\u0435 HTTP\/2, \u0430 RabbitMQ. \u0412\u0441\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u043d\u043e \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u044b\u043b\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0437-\u0437\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 grpcurl. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0438\u0442\u043e\u0433\u0435 \u043e\u0442 Protocol Buffers \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043a JSON-\u0430\u043c, \u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0441 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u043d\u043e\u0434\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u0440\u044f\u043c\u044b\u043c\u0438 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u043e\u0431\u043e\u0448\u043b\u0438\u0441\u044c. \u041c\u043e\u0440\u0430\u043b\u044c: \u0435\u0441\u043b\u0438 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c gRPC, \u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u043e\u043b\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u0435, &#171;wanna be gRPC&#187; \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0439 \u043a\u043e\u043d\u0442\u0430\u043a\u0442 \u0441 subj \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0438\u043b\u0441\u044f \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438: \u043c\u0435\u043d\u044f \u0441\u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u043f\u0440\u043e \u0443\u043c\u0435\u043d\u0438\u044f \u0432 gRPC, \u0438 \u0442\u0443\u0442 \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0431\u044b\u043b\u043e\u00a0\u043d\u0430 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442. \u0411\u044b\u043b\u043e \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u043e\u0441\u0430\u0434\u043e\u0432\u0430\u043d (\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u043e\u043c, \u0430 \u0442\u0430\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f server-server \u043f\u043e\u0432\u0441\u044e\u0434\u0443 \u0438 gRPC \u0432\u0435\u0441\u044c\u043c\u0430 \u0443\u043c\u0435\u0441\u0442\u0435\u043d). \u0425\u043e\u0442\u044c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e \u0438 \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u043e\u0441\u0430\u0434\u043e\u043a \u0443 \u043c\u0435\u043d\u044f \u043e\u0441\u0442\u0430\u043b\u0441\u044f.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>\u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u043a\u0441\u0438 \u044f \u0431\u044b\u043b \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d <a href=\"https:\/\/medium.com\/@mlowicki\/http-s-proxy-in-golang-in-less-than-100-lines-of-code-6a51c2f2c38c\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435\u0439<\/a> Micha\u0142 \u0141owicki, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e 100 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440. \u041f\u043e \u0444\u0430\u043a\u0442\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0437 2 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443:<\/p>\n<pre><code class=\"go\">func handleTunneling(w http.ResponseWriter, r *http.Request) {     dest_conn, err := net.DialTimeout(\"tcp\", r.Host, 10*time.Second)     if err != nil {         http.Error(w, err.Error(), http.StatusServiceUnavailable)         return     }     w.WriteHeader(http.StatusOK)     hijacker, ok := w.(http.Hijacker)     if !ok {         http.Error(w, \"Hijacking not supported\", http.StatusInternalServerError)         return     }     client_conn, _, err := hijacker.Hijack()     if err != nil {         http.Error(w, err.Error(), http.StatusServiceUnavailable)     }     go transfer(dest_conn, client_conn)     go transfer(client_conn, dest_conn) }  func transfer(destination io.WriteCloser, source io.ReadCloser) {     defer destination.Close()     defer source.Close()     io.Copy(destination, source) } <\/code><\/pre>\n<p>\u0417\u043d\u0430\u0439 \u0441\u0435\u0431\u0435 \u0437\u0430-deploy \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430 Cloud Run, \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 (\u0438 gRPC \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f). \u0427\u0442\u043e \u044f \u043d\u0435\u043c\u0435\u0434\u043b\u044f \u0438 \u0441\u0434\u0435\u043b\u0430\u043b. \u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e: \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c CONNECT, \u0430 \u043e\u043d (\u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e?) \u0437\u0430\u0431\u0430\u043d\u0435\u043d \u043d\u0430 Cloud Run.<\/p>\n<p>\u041d\u0443 \u0445\u043e\u0440\u043e\u0448\u043e, \u0437\u043d\u0430\u0447\u0438\u0442 \u0430) \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043d\u0435\u043b\u044c\u0437\u044f \u0438 \u0431\u0435\u0437 gRPC \u043d\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431) \u0434\u0430\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043c\u0435\u043d\u044c\u0448\u0435 &#171;\u043c\u0430\u043c\u043a\u0438\u043d\u044b\u0445&#187; \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u043e\u0432 \u0441\u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0445\u043e\u0434\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 GCP.<\/p>\n<p>\u041f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0431\u0435 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0443\u044e \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u0438 (\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e gRPC), \u0447\u0442\u043e \u044f \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0438 \u0441\u0434\u0435\u043b\u0430\u043b.<\/p>\n<h3>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<h4>h2c-\u0444\u043e\u0440\u043c\u0430\u0442<\/h4>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0432\u043d\u0443\u0442\u0440\u0438 gRPC-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0430\u043c \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <a href=\"https:\/\/grpc.io\/docs\/what-is-grpc\/core-concepts\/#bidirectional-streaming-rpc\" rel=\"noopener noreferrer nofollow\">bidirectional streaming<\/a>. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 <a href=\"https:\/\/gitverse.ru\/muravjov\/pog-server\/content\/master\/grpcproxy\/proto\/v1\/grpcproxy.proto\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a<\/a>:<\/p>\n<pre><code>service HTTPProxy {   rpc Run(stream Packet) returns (stream Packet) {} } <\/code><\/pre>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e Cloud Run \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 \u0444\u043e\u0440\u043c\u0430\u0442 <a href=\"https:\/\/cloud.google.com\/run\/docs\/configuring\/http2\" rel=\"noopener noreferrer nofollow\">h2c<\/a>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u0430 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 HTTP\/2. \u0411\u0435\u0437 \u044d\u0442\u043e\u0433\u043e \u0444\u043b\u0430\u0433\u0430 \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e HTTP\/1 \u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0441\u0435\u0440\u0432\u0438\u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<pre><code class=\"bash\">$ gcloud run services describe pog-server --format=export | grep -A3 ports         ports:         - containerPort: 8080           name: h2c         resources: <\/code><\/pre>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435, \u0432 gPRC-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0436\u0435\u0441\u0442\u043a\u043e \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d \u0442\u043e\u043b\u044c\u043a\u043e (\u0440\u0430\u0441\u043e\u0432\u043e \u0432\u0435\u0440\u043d\u044b\u0439) \u0444\u043e\u0440\u043c\u0430\u0442 h2, \u043d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e h2c (\u0440\u0430\u0434\u0443\u0435\u043c\u0441\u044f \u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0441\u0442\u044c).<\/p>\n<h4>\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c\u0438<\/h4>\n<p>\u041a\u0430\u0436\u0434\u043e\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u043c\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438:<\/p>\n<ol>\n<li>\n<p>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c &lt;=> pog-client<\/p>\n<\/li>\n<li>\n<p>pog-client &lt;=gRPC=> pog-server<\/p>\n<\/li>\n<li>\n<p>pog-server &lt;=> \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u043b \u0440\u0430\u0437\u0440\u044b\u0432 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0438\u043b\u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 2, \u0438\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0442\u0435\u0447\u043a\u0430 (\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439, \u043f\u0430\u043c\u044f\u0442\u0438). \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043a\u0430\u043a \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c gRPC \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c: \u0435\u0441\u043b\u0438 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 stream.CloseSend() \u0438\u043b\u0438 \u0430\u043d\u0430\u043b\u043e\u0433, \u0442\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u0442, \u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e <code>\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0439\u0442\u0438 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430<\/code> gRPC.<\/p>\n<p>\u041a\u043e\u043b-\u0432\u043e \u0442\u0435\u043a\u0443\u0449\u0438\u0445 HTTP-\u0441\u0435\u0441\u0441\u0438\u0439 \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430, \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">$ curl -is http:\/\/localhost:18080\/metrics | grep tunnelling # HELP pog_client_tunnelling_connections_total Number of connections tunneling through the proxy. # TYPE pog_client_tunnelling_connections_total gauge pog_client_tunnelling_connections_total 28 # HELP tunnelling_connections_total Number of connections tunneling through the proxy. # TYPE tunnelling_connections_total gauge tunnelling_connections_total 28 <\/code><\/pre>\n<h4>HTTP-\u0441\u0435\u0440\u0432\u0435\u0440 \u0438 gRPC-\u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0440\u0442\u0443<\/h4>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435, \u043d\u0430 Go \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 3 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 gRPC:<\/p>\n<ul>\n<li>\n<p>go-grpc: <\/p>\n<ul>\n<li>\n<p>\u044d\u0442\u043e \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 HTTP\/2<\/p>\n<\/li>\n<li>\n<p>\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043b\u044e\u0448\u0435\u043a \u0432\u043d\u0443\u0442\u0440\u0438 (codecs &amp; plugins)<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 &#171;net\/http&#187; (\u0442\u043e\u043b\u044c\u043a\u043e HTTP\/2-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f) + \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0437 grpc-go <code>func ServeHTTP(w http.ResponseWriter, r *http.Request)<\/code>: <\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0440\u0442\u0443 \u0432\u0435\u0448\u0430\u0442\u044c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440 gRPC,\u00a0\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 HTTP<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439, \u0441\u043c. <a href=\"https:\/\/github.com\/grpc\/grpc-go\/blob\/v1.60.1\/server.go#L1061\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0434<\/a><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"https:\/\/connectrpc.com\/docs\/go\/getting-started\" rel=\"noopener noreferrer nofollow\">\u0445\u0438\u043f\u0441\u0442\u0435\u0440\u0441\u043a\u0438\u0439<\/a>: <\/p>\n<ul>\n<li>\n<p>\u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0434\u0438\u0437\u0430\u0439\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c gRPC-\u043a\u043e\u0434 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u0438 HTTP<\/p>\n<\/li>\n<li>\n<p>\u0438\u043d\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u0434\u0430 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 (\u0441 Go-\u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438)<\/p>\n<\/li>\n<li>\n<p>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 &#171;net\/http&#187; \u0438 \u0441\u0432\u043e\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 gRPC<\/p>\n<\/li>\n<li>\n<p>\u043c\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a\u0430\u043a \u0442\u0435\u0441\u0442\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e curl, grpcurl \u0438 \u043f\u0440\u043e\u0447\u0435\u0435<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>pog-server \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0447\u0438\u0442\u0430\u0442\u044c Prometheus-\u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0430 \/metrics.<\/p>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e grpctest<\/h4>\n<p>\u0417\u0430 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0430\u043d\u0430\u043b\u043e\u0433\u0430 &#171;net\/http\/httptest&#187;, \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0441\u0432\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 <a href=\"https:\/\/gitverse.ru\/muravjov\/pog-server\/content\/master\/grpctest\/server.go\" rel=\"noopener noreferrer nofollow\">grpctest<\/a>. \u042d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c unit-\u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f gRPC-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"go\">func TestGStacks(t *testing.T) {    \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440    server := grpc.NewServer()    RegisterGStacksSvc(server)     \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c    sc, err := grpctest.StartServerClient(server)    require.NoError(t, err)    defer sc.Close()     \/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441    client := pb.NewGoroutineStacksClient(sc.Conn)    resp, err := client.Invoke(context.Background(), &amp;pb.Request{})    require.NoError(t, err)     \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442    fmt.Println(resp.Data) } <\/code><\/pre>\n<h3>\u0420\u0430\u0437\u043d\u043e\u0435<\/h3>\n<ul>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 CONNECT \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 HTTPS-\u0430\u0434\u0440\u0435\u0441\u043e\u0432, \u0430 \u0434\u043b\u044f HTTP \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0438\u043d\u0430\u0447\u0435, \u0441\u043c. <a href=\"https:\/\/medium.com\/@mlowicki\/http-s-proxy-in-golang-in-less-than-100-lines-of-code-6a51c2f2c38c\" rel=\"noopener noreferrer nofollow\">handleHTTP<\/a>. \u0414\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 HTTP\u00a0\u043c\u0430\u043b\u043e\u0430\u043a\u0442\u0443\u0430\u043b\u0435\u043d, \u043f\u043e\u0442\u043e\u043c\u0443 (\u043f\u043e\u043a\u0430?) \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u0434\u043b\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 gRPC \u043c\u0430\u043b\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438\u043d\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 &#171;\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0448\u044c\u0441\u044f&#187;; \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a grpcurl \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442 \u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c (\u043c\u043e\u0433\u0443 \u043e\u0448\u0438\u0431\u0430\u0442\u044c\u0441\u044f). \u041d\u0430\u0434\u0435\u044e\u0441\u044c, <code>pog-server<\/code> \u0443\u043b\u0443\u0447\u0448\u0438\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/822189\/\"> https:\/\/habr.com\/ru\/articles\/822189\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"\"><\/figure>\n<p>HTTP-\u043f\u0440\u043e\u043a\u0441\u0438 &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0434\u043b\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0433\u043e IP-\u0430\u0434\u0440\u0435\u0441\u0430.<\/p>\n<p>gRPC &#8212; \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 HTTP\/2-\u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0435 \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u044f\u0437\u044b\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0430\u044f <em>Protocol Buffers<\/em>.<\/p>\n<p>\u042f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b HTTP-\u043f\u0440\u043e\u043a\u0441\u0438 <a href=\"https:\/\/gitverse.ru\/muravjov\/pog-server\" rel=\"noopener noreferrer nofollow\">pog-server<\/a>, \u0432\u044b\u043b\u043e\u0436\u0438\u043b \u0432 Open Source \u0438 \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0435\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u0430\u0439\u0442\u044b \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c gRPC:<\/p>\n<pre><code>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c &lt;=> pog-client &lt;=gRPC=> pog-server &lt;=> \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440 <\/code><\/pre>\n<h3>\u0417\u0430\u0447\u0435\u043c<\/h3>\n<p>\u0412 \u043d\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u042f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u043e\u0434\u043d\u0438\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f \u043a ChatGPT: \u0442\u0430\u043a \u0443 \u043c\u0435\u043d\u044f \u0441\u0442\u0430\u043b\u043e 2 \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0441\u044f Terraform. \u041e\u043d \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u043e\u0434 \u043e\u0434\u043d\u0438\u043c \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code>$ export HTTPS_PROXY=http:\/\/west.catbo.net:18080 $ terraform init <\/code><\/pre>\n<p>; \u043e\u0434\u043d\u0430\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u044d\u0442\u0438\u043c \u044f \u0434\u0435\u043b\u0430\u043b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a Google API, \u0438 \u0442\u043e\u0442 \u0437\u0430\u0431\u0440\u0430\u043a\u043e\u0432\u0430\u043b \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440. \u0422\u0430\u043a \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0438 \u043a\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\u0422\u0430\u043a \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u0439\u0442\u0438 \u0442\u0430\u043a\u043e\u0439 \u043a\u0440\u0438\u0441\u0442\u0430\u043b\u044c\u043d\u043e \u0447\u0438\u0441\u0442\u044b\u0439 IP, \u0447\u0442\u043e\u0431\u044b \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u0431\u044b\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0432\u044b\u0448\u0435 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u0443 \u043d\u0430\u0441 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430 <a href=\"https:\/\/console.cloud.google.com\/\" rel=\"noopener noreferrer nofollow\">GCP<\/a>, \u0442\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0441\u0442\u0430\u043b \u0431\u044b \u0441\u0435\u0440\u0432\u0438\u0441 <code>Cloud Run<\/code>, \u0438\u0433\u0440\u0430\u044e\u0449\u0438\u0439 \u0440\u043e\u043b\u044c \u043f\u0440\u043e\u043a\u0441-\u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434. \u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, &#171;let\u2019s make this world a better place&#187;.<\/p>\n<h3>gRPC. \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043e\u043f\u044b\u0442<\/h3>\n<p>\u041d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0431\u044b\u043b \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d gRPC: \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u043d\u043e\u0434\u044b \u0434\u043e edge-\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Protocol Buffers. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c gRPC \u0431\u044b\u043b\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0440\u0430\u0441\u043f\u043e\u0440\u0442\u0430 \u0431\u044b\u043b \u043d\u0435 HTTP\/2, \u0430 RabbitMQ. \u0412\u0441\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u043d\u043e \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u044b\u043b\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0437-\u0437\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 grpcurl. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0438\u0442\u043e\u0433\u0435 \u043e\u0442 Protocol Buffers \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043a JSON-\u0430\u043c, \u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0441 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u043d\u043e\u0434\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u0440\u044f\u043c\u044b\u043c\u0438 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u043e\u0431\u043e\u0448\u043b\u0438\u0441\u044c. \u041c\u043e\u0440\u0430\u043b\u044c: \u0435\u0441\u043b\u0438 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c gRPC, \u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u043e\u043b\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u0435, &#171;wanna be gRPC&#187; \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0439 \u043a\u043e\u043d\u0442\u0430\u043a\u0442 \u0441 subj \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0438\u043b\u0441\u044f \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438: \u043c\u0435\u043d\u044f \u0441\u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u043f\u0440\u043e \u0443\u043c\u0435\u043d\u0438\u044f \u0432 gRPC, \u0438 \u0442\u0443\u0442 \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0431\u044b\u043b\u043e\u00a0\u043d\u0430 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442. \u0411\u044b\u043b\u043e \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u043e\u0441\u0430\u0434\u043e\u0432\u0430\u043d (\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u043e\u043c, \u0430 \u0442\u0430\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f server-server \u043f\u043e\u0432\u0441\u044e\u0434\u0443 \u0438 gRPC \u0432\u0435\u0441\u044c\u043c\u0430 \u0443\u043c\u0435\u0441\u0442\u0435\u043d). \u0425\u043e\u0442\u044c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e \u0438 \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u043e\u0441\u0430\u0434\u043e\u043a \u0443 \u043c\u0435\u043d\u044f \u043e\u0441\u0442\u0430\u043b\u0441\u044f.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>\u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u043a\u0441\u0438 \u044f \u0431\u044b\u043b \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d <a href=\"https:\/\/medium.com\/@mlowicki\/http-s-proxy-in-golang-in-less-than-100-lines-of-code-6a51c2f2c38c\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435\u0439<\/a> Micha\u0142 \u0141owicki, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e 100 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440. \u041f\u043e \u0444\u0430\u043a\u0442\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0437 2 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443:<\/p>\n<pre><code class=\"go\">func handleTunneling(w http.ResponseWriter, r *http.Request) {     dest_conn, err := net.DialTimeout(\"tcp\", r.Host, 10*time.Second)     if err != nil {         http.Error(w, err.Error(), http.StatusServiceUnavailable)         return     }     w.WriteHeader(http.StatusOK)     hijacker, ok := w.(http.Hijacker)     if !ok {         http.Error(w, \"Hijacking not supported\", http.StatusInternalServerError)         return     }     client_conn, _, err := hijacker.Hijack()     if err != nil {         http.Error(w, err.Error(), http.StatusServiceUnavailable)     }     go transfer(dest_conn, client_conn)     go transfer(client_conn, dest_conn) }  func transfer(destination io.WriteCloser, source io.ReadCloser) {     defer destination.Close()     defer source.Close()     io.Copy(destination, source) } <\/code><\/pre>\n<p>\u0417\u043d\u0430\u0439 \u0441\u0435\u0431\u0435 \u0437\u0430-deploy \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430 Cloud Run, \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 (\u0438 gRPC \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f). \u0427\u0442\u043e \u044f \u043d\u0435\u043c\u0435\u0434\u043b\u044f \u0438 \u0441\u0434\u0435\u043b\u0430\u043b. \u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e: \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c CONNECT, \u0430 \u043e\u043d (\u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e?) \u0437\u0430\u0431\u0430\u043d\u0435\u043d \u043d\u0430 Cloud Run.<\/p>\n<p>\u041d\u0443 \u0445\u043e\u0440\u043e\u0448\u043e, \u0437\u043d\u0430\u0447\u0438\u0442 \u0430) \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043d\u0435\u043b\u044c\u0437\u044f \u0438 \u0431\u0435\u0437 gRPC \u043d\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431) \u0434\u0430\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043c\u0435\u043d\u044c\u0448\u0435 &#171;\u043c\u0430\u043c\u043a\u0438\u043d\u044b\u0445&#187; \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u043e\u0432 \u0441\u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0445\u043e\u0434\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 GCP.<\/p>\n<p>\u041f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0431\u0435 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0443\u044e \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u0438 (\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e gRPC), \u0447\u0442\u043e \u044f \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0438 \u0441\u0434\u0435\u043b\u0430\u043b.<\/p>\n<h3>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<h4>h2c-\u0444\u043e\u0440\u043c\u0430\u0442<\/h4>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0432\u043d\u0443\u0442\u0440\u0438 gRPC-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0430\u043c \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <a href=\"https:\/\/grpc.io\/docs\/what-is-grpc\/core-concepts\/#bidirectional-streaming-rpc\" rel=\"noopener noreferrer nofollow\">bidirectional streaming<\/a>. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 <a href=\"https:\/\/gitverse.ru\/muravjov\/pog-server\/content\/master\/grpcproxy\/proto\/v1\/grpcproxy.proto\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a<\/a>:<\/p>\n<pre><code>service HTTPProxy {   rpc Run(stream Packet) returns (stream Packet) {} } <\/code><\/pre>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e Cloud Run \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 \u0444\u043e\u0440\u043c\u0430\u0442 <a href=\"https:\/\/cloud.google.com\/run\/docs\/configuring\/http2\" rel=\"noopener noreferrer nofollow\">h2c<\/a>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u0430 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 HTTP\/2. \u0411\u0435\u0437 \u044d\u0442\u043e\u0433\u043e \u0444\u043b\u0430\u0433\u0430 \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e HTTP\/1 \u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0441\u0435\u0440\u0432\u0438\u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<pre><code class=\"bash\">$ gcloud run services describe pog-server --format=export | grep -A3 ports         ports:         - containerPort: 8080           name: h2c         resources: <\/code><\/pre>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435, \u0432 gPRC-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0436\u0435\u0441\u0442\u043a\u043e \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d \u0442\u043e\u043b\u044c\u043a\u043e (\u0440\u0430\u0441\u043e\u0432\u043e \u0432\u0435\u0440\u043d\u044b\u0439) \u0444\u043e\u0440\u043c\u0430\u0442 h2, \u043d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e h2c (\u0440\u0430\u0434\u0443\u0435\u043c\u0441\u044f \u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0441\u0442\u044c).<\/p>\n<h4>\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c\u0438<\/h4>\n<p>\u041a\u0430\u0436\u0434\u043e\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u043c\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438:<\/p>\n<ol>\n<li>\n<p>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c &lt;=> pog-client<\/p>\n<\/li>\n<li>\n<p>pog-client &lt;=gRPC=> pog-server<\/p>\n<\/li>\n<li>\n<p>pog-server &lt;=> \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u043b \u0440\u0430\u0437\u0440\u044b\u0432 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0438\u043b\u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 2, \u0438\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0442\u0435\u0447\u043a\u0430 (\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439, \u043f\u0430\u043c\u044f\u0442\u0438). \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043a\u0430\u043a \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c gRPC \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c: \u0435\u0441\u043b\u0438 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 stream.CloseSend() \u0438\u043b\u0438 \u0430\u043d\u0430\u043b\u043e\u0433, \u0442\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u0442, \u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e <code>\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0439\u0442\u0438 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430<\/code> gRPC.<\/p>\n<p>\u041a\u043e\u043b-\u0432\u043e \u0442\u0435\u043a\u0443\u0449\u0438\u0445 HTTP-\u0441\u0435\u0441\u0441\u0438\u0439 \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430, \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">$ curl -is http:\/\/localhost:18080\/metrics | grep tunnelling # HELP pog_client_tunnelling_connections_total Number of connections tunneling through the proxy. # TYPE pog_client_tunnelling_connections_total gauge pog_client_tunnelling_connections_total 28 # HELP tunnelling_connections_total Number of connections tunneling through the proxy. # TYPE tunnelling_connections_total gauge tunnelling_connections_total 28 <\/code><\/pre>\n<h4>HTTP-\u0441\u0435\u0440\u0432\u0435\u0440 \u0438 gRPC-\u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0440\u0442\u0443<\/h4>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435, \u043d\u0430 Go \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 3 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 gRPC:<\/p>\n<ul>\n<li>\n<p>go-grpc: <\/p>\n<ul>\n<li>\n<p>\u044d\u0442\u043e \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 HTTP\/2<\/p>\n<\/li>\n<li>\n<p>\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043b\u044e\u0448\u0435\u043a \u0432\u043d\u0443\u0442\u0440\u0438 (codecs &amp; plugins)<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 &#171;net\/http&#187; (\u0442\u043e\u043b\u044c\u043a\u043e HTTP\/2-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f) + \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0437 grpc-go <code>func ServeHTTP(w http.ResponseWriter, r *http.Request)<\/code>: <\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0440\u0442\u0443 \u0432\u0435\u0448\u0430\u0442\u044c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440 gRPC,\u00a0\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 HTTP<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439, \u0441\u043c. <a href=\"https:\/\/github.com\/grpc\/grpc-go\/blob\/v1.60.1\/server.go#L1061\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0434<\/a><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"https:\/\/connectrpc.com\/docs\/go\/getting-started\" rel=\"noopener noreferrer nofollow\">\u0445\u0438\u043f\u0441\u0442\u0435\u0440\u0441\u043a\u0438\u0439<\/a>: <\/p>\n<ul>\n<li>\n<p>\u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0434\u0438\u0437\u0430\u0439\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c gRPC-\u043a\u043e\u0434 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u0438 HTTP<\/p>\n<\/li>\n<li>\n<p>\u0438\u043d\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u0434\u0430 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 (\u0441 Go-\u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438)<\/p>\n<\/li>\n<li>\n<p>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 &#171;net\/http&#187; \u0438 \u0441\u0432\u043e\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 gRPC<\/p>\n<\/li>\n<li>\n<p>\u043c\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a\u0430\u043a \u0442\u0435\u0441\u0442\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e curl, grpcurl \u0438 \u043f\u0440\u043e\u0447\u0435\u0435<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>pog-server \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0447\u0438\u0442\u0430\u0442\u044c Prometheus-\u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0430 \/metrics.<\/p>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e grpctest<\/h4>\n<p>\u0417\u0430 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0430\u043d\u0430\u043b\u043e\u0433\u0430 &#171;net\/http\/httptest&#187;, \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0441\u0432\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 <a href=\"https:\/\/gitverse.ru\/muravjov\/pog-server\/content\/master\/grpctest\/server.go\" rel=\"noopener noreferrer nofollow\">grpctest<\/a>. \u042d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c unit-\u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f gRPC-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"go\">func TestGStacks(t *testing.T) {    \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440    server := grpc.NewServer()    RegisterGStacksSvc(server)     \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c    sc, err := grpctest.StartServerClient(server)    require.NoError(t, err)    defer sc.Close()     \/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441    client := pb.NewGoroutineStacksClient(sc.Conn)    resp, err := client.Invoke(context.Background(), &amp;pb.Request{})    require.NoError(t, err)     \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442    fmt.Println(resp.Data) } <\/code><\/pre>\n<h3>\u0420\u0430\u0437\u043d\u043e\u0435<\/h3>\n<ul>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 CONNECT \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 HTTPS-\u0430\u0434\u0440\u0435\u0441\u043e\u0432, \u0430 \u0434\u043b\u044f HTTP \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0438\u043d\u0430\u0447\u0435, \u0441\u043c. <a href=\"https:\/\/medium.com\/@mlowicki\/http-s-proxy-in-golang-in-less-than-100-lines-of-code-6a51c2f2c38c\" rel=\"noopener noreferrer nofollow\">handleHTTP<\/a>. \u0414\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 HTTP\u00a0\u043c\u0430\u043b\u043e\u0430\u043a\u0442\u0443\u0430\u043b\u0435\u043d, \u043f\u043e\u0442\u043e\u043c\u0443 (\u043f\u043e\u043a\u0430?) \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u0434\u043b\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 gRPC \u043c\u0430\u043b\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438\u043d\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 &#171;\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0448\u044c\u0441\u044f&#187;; \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a grpcurl \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442 \u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c (\u043c\u043e\u0433\u0443 \u043e\u0448\u0438\u0431\u0430\u0442\u044c\u0441\u044f). \u041d\u0430\u0434\u0435\u044e\u0441\u044c, <code>pog-server<\/code> \u0443\u043b\u0443\u0447\u0448\u0438\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/822189\/\"> https:\/\/habr.com\/ru\/articles\/822189\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-379009","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=379009"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379009\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}