{"id":43149,"date":"2024-12-01T15:02:52","date_gmt":"2024-12-01T07:02:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/43149\/"},"modified":"2024-12-01T15:02:52","modified_gmt":"2024-12-01T07:02:52","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e6%ad%a4%e5%8a%9f%e8%83%bd%e9%83%a8%e7%bd%b2%e5%88%b0%e8%b0%b7%e6%ad%8c%e4%ba%91%e4%b8%8a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/43149\/","title":{"rendered":"\u5982\u4f55\u5c06\u6b64\u529f\u80fd\u90e8\u7f72\u5230\u8c37\u6b4c\u4e91\u4e0a\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5982\u4f55\u5c06\u6b64\u529f\u80fd\u90e8\u7f72\u5230\u8c37\u6b4c\u4e91\u4e0a\uff1f<\/span><\/p>\n<h1>\u5982\u4f55\u5c06\u6b64\u529f\u80fd\u90e8\u7f72\u5230\u8c37\u6b4c\u4e91\u4e0a\uff1f<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-30 08:36:33<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u600e\u4e48\u5165\u95e8Golang\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300a\u5982\u4f55\u5c06\u6b64\u529f\u80fd\u90e8\u7f72\u5230\u8c37\u6b4c\u4e91\u4e0a\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u8fd9\u4e2aapi\u53ef\u4ee5\u90e8\u7f72\u5230google\u4e91\u51fd\u6570\u5417\uff1f<\/p>\n<p>https:\/\/github.com\/Mdsp9070\/someoneFlix\/tree\/master\/backend<\/p>\n<p>\u6211\u5c1d\u8bd5\u90e8\u7f72\uff0c\u4f46\u6536\u5230\u6b64\u9519\u8bef\uff1a <code>ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: main.go:16:2: import \"flix-api.localhost\/flix-api\" \u662f\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u800c\u4e0d\u662f\u53ef\u5bfc\u5165\u7684\u5305\uff1b\u9519\u8bef ID\uff1a975560ac<\/code><\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u5fc5\u987b\u5b9e\u73b0\u6b63\u786e\u7684\u7b7e\u540d\u6765\u5904\u7406\u51fd\u6570\u8bf7\u6c42<\/p>\n<pre>func myfunction(w http.responsewriter, r *http.request) {\n...\n}<\/pre>\n<p>\u5728\u8fd9\u91cc\uff0c\u60a8\u53ef\u4ee5\u542f\u52a8\u81ea\u5df1\u7684\u5177\u6709\u591a\u4e2a\u7aef\u70b9\u7684 web \u670d\u52a1\u5668\u3002\u5b83\u4e0d\u662f cloud functions \u6a21\u5f0f\uff0c\u800c\u66f4\u50cf\u662f  \u670d\u52a1\u3002\u8bd5\u8bd5\u8fd9\u4e2a\uff08\u4f7f\u7528\u6b63\u786e\u7684 projectid\uff09<\/p>\n<pre>gcloud alpha builds submit --pack=image=gcr.io\/PROJECT_ID\/backend &amp;&amp; \\\ngcloud run deploy --platform=managed --region=us-central1 --image=gcr.io\/PROJECT_ID\/backend --port=3333 --allow-unauthenticated backend<\/pre>\n<p>\u5e76\u8c03\u7528\u63d0\u4f9b\u7684 url\u3002\u6211\u7528\u4f60\u7684\u4ee3\u7801\u8fdb\u884c\u4e86\u6d4b\u8bd5\uff0c\u5b83\u5728\u6211\u8fd9\u8fb9\u5de5\u4f5c\uff0c\u6211\u521a\u521a\u5728 loadinf .env file \u4e0a\u7684\u65e5\u5fd7 <code>error \u4e2d\u6536\u5230\u9519\u8bef\u3002\u60a8\u53ef\u80fd\u9700\u8981\u8bbe\u7f6e <code>--set-env-vars<\/code> \u4ee5\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\u3002<\/code><\/p>\n<p>\u5982\u679c\u6709\u5174\u8da3\uff0c\u6211\u53ef\u4ee5\u89e3\u91ca\u66f4\u591a\u547d\u4ee4<\/p>\n<p><strong>\u7f16\u8f91<\/strong><\/p>\n<p>\u4e00\u4e9b\u89e3\u91ca<\/p>\n<ol>\n<li>cloud functions \u548c cloud build \u5171\u4eab\u76f8\u540c\u7684\u540e\u7aef\u3002 cloud run \u6258\u7ba1\u4e00\u4e2a\u7f51\u7edc\u670d\u52a1\u5668\uff08\u5728\u53ef\u81ea\u5b9a\u4e49\u7684\u5bb9\u5668\u4e2d\uff09\u3002 cloud function \u5c06\u51fd\u6570\u6253\u5305\u5230 web \u670d\u52a1\u5668\u4e2d\uff08\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u60a8\u5fc5\u987b\u5c0a\u91cd\u51fd\u6570\u7b7e\u540d\u4ee5\u4f7f\u5176\u53ef\u7531\u901a\u7528 web \u670d\u52a1\u5668\u8c03\u7528\uff09\u3002<\/li>\n<li>cloud run \u53ef\u4ee5\u5904\u7406\u540c\u4e00\u5b9e\u4f8b\u4e2d\u7684\u5e76\u53d1\u8bf7\u6c42\uff08\u6700\u591a 80 \u4e2a\uff09\uff0c\u800c cloud functions \u53ea\u80fd\u5904\u7406 1 \u4e2a\u3002\u5982\u679c\u5c06 cloud run \u5e76\u53d1\u53c2\u6570\u8bbe\u7f6e\u4e3a 1\uff0c\u60a8\u53ef\u4ee5\u83b7\u5f97\u5b8c\u5168\u76f8\u540c\u7684\u884c\u4e3a<\/li>\n<li>cloud run \u9700\u8981\u4e00\u4e2a\u5bb9\u5668\u3002\u5f53\u60a8\u62e5\u6709\u4ee3\u7801\u65f6\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199 \u3002\u60a8\u53ef\u4ee5\u4f7f\u7528  \u6216  \u6784\u5efa\u5bb9\u5668\u3002\u5728\u6211\u7684\u4ee3\u7801\u793a\u4f8b\u4e2d\uff0c\u6211\u4f7f\u7528\u4e86\u57fa\u4e8e  \u7684 cloud build \u7684 alpha\uff08\u4e14\u672a\u8bb0\u5f55\u7684\u547d\u4ee4\uff09\u3002\u6784\u5efa\u5305\u68c0\u6d4b\u60a8\u7684\u8bed\u8a00\uff0c\u4e3b\u6587\u4ef6\u5e76\u6839\u636e\u60a8\u7684\u4ee3\u7801\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u6807\u51c6\u5bb9\u5668\u3002\u975e\u5e38\u9002\u5408\u5feb\u901f\u6d4b\u8bd5\u548c\u4e0d\u9700\u8981\u5b9a\u5236\u7684\u5bb9\u5668\u3002<\/li>\n<\/ol>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8eGolang\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u5982\u4f55\u5c06\u6b64\u529f\u80fd\u90e8\u7f72\u5230\u8c37\u6b4c\u4e91\u4e0a\uff1f \u5982\u4f55\u5c06\u6b64\u529f\u80fd\u90e8\u7f72\u5230\u8c37\u6b4c\u4e91\u4e0a\uff1f \u6765\u6e90\uff1astackoverflow 2024-04-30 08:36:33 0\u6d4f\u89c8 \u6536\u85cf \u600e\u4e48\u5165\u95e8Golang\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300a\u5982\u4f55\u5c06\u6b64\u529f\u80fd\u90e8\u7f72\u5230\u8c37\u6b4c\u4e91\u4e0a\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b \u95ee\u9898\u5185\u5bb9 \u8fd9\u4e2aapi\u53ef\u4ee5\u90e8\u7f72\u5230google\u4e91\u51fd\u6570\u5417\uff1f https:\/\/github.com\/Mdsp9070\/someoneFlix\/tree\/master\/backend \u6211\u5c1d\u8bd5\u90e8\u7f72\uff0c\u4f46\u6536\u5230\u6b64\u9519\u8bef\uff1a ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: main.go:16:2: import &#8220;flix-api.localhost\/flix-api&#8221; \u662f\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u800c\u4e0d\u662f\u53ef\u5bfc\u5165\u7684\u5305\uff1b\u9519\u8bef ID\uff1a975560ac \u89e3\u51b3\u65b9\u6848 \u60a8\u5fc5\u987b\u5b9e\u73b0\u6b63\u786e\u7684\u7b7e\u540d\u6765\u5904\u7406\u51fd\u6570\u8bf7\u6c42 func myfunction(w http.responsewriter, r *http.request) { &#8230; } \u5728\u8fd9\u91cc\uff0c\u60a8\u53ef\u4ee5\u542f\u52a8\u81ea\u5df1\u7684\u5177\u6709\u591a\u4e2a\u7aef\u70b9\u7684 web \u670d\u52a1\u5668\u3002\u5b83\u4e0d\u662f cloud functions \u6a21\u5f0f\uff0c\u800c\u66f4\u50cf\u662f \u670d\u52a1\u3002\u8bd5\u8bd5\u8fd9\u4e2a\uff08\u4f7f\u7528\u6b63\u786e\u7684 projectid\uff09 gcloud alpha builds submit &#8211;pack=image=gcr.io\/PROJECT_ID\/backend &amp;&amp; \\ gcloud run [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-43149","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=43149"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43149\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=43149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=43149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=43149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}