{"id":6668,"date":"2023-08-28T17:50:37","date_gmt":"2023-08-28T09:50:37","guid":{"rendered":"https:\/\/h5app.yimenapp.cn\/h5app\/?p=6668"},"modified":"2023-08-28T17:50:37","modified_gmt":"2023-08-28T09:50:37","slug":"goappengine%e6%89%93%e5%8c%85%e6%93%8d%e4%bd%9c%e6%b5%81%e7%a8%8b%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/h5app.yimenapp.cn\/h5app\/2023\/sjapp\/6668\/","title":{"rendered":"goappengine\u6253\u5305\u64cd\u4f5c\u6d41\u7a0b\u4ecb\u7ecd"},"content":{"rendered":"<p>GoAppEngine \u662f Google App Engine \u7684 Go \u8bed\u8a00\u7248\u672c\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4f7f\u7528 Go \u8bed\u8a00\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u5e76\u90e8\u7f72\u5230 Google App Engine \u5e73\u53f0\u4e0a\u3002GoAppEngine \u7684\u90e8\u7f72\u65b9\u5f0f\u4e0e\u5176\u4ed6\u8bed\u8a00\u7248\u672c\u7565\u6709\u4e0d\u540c\uff0c\u9700\u8981\u8fdb\u884c\u6253\u5305\u64cd\u4f5c\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd GoAppEngine \u7684\u6253\u5305\u539f\u7406\u53ca\u8be6\u7ec6\u64cd\u4f5c\u6d41\u7a0b\u3002<\/p>\n<p>## \u6253\u5305\u539f\u7406<\/p>\n<p>GoAppEngine \u7684\u6253\u5305\u8fc7\u7a0b\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<p>1. \u7f16\u8bd1\u5e94\u7528\u7a0b\u5e8f\uff1a\u4f7f\u7528 Go \u7684\u7f16\u8bd1\u5668\u5c06\u5e94\u7528\u7a0b\u5e8f\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff1b<\/p>\n<p>2. \u590d\u5236\u4f9d\u8d56\u5e93\uff1a\u5c06\u5e94\u7528\u7a0b\u5e8f\u6240\u4f9d\u8d56\u7684\u5e93\u6587\u4ef6\u590d\u5236\u5230\u6307\u5b9a\u76ee\u5f55\uff1b<\/p>\n<p>3. \u751f\u6210\u914d\u7f6e\u6587\u4ef6\uff1a\u751f\u6210\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u6587\u4ef6 app.yaml\uff1b<\/p>\n<p>4. \u538b\u7f29\u6587\u4ef6\uff1a\u5c06\u6240\u6709\u6587\u4ef6\u6253\u5305\u6210 ZIP \u6587\u4ef6\u3002<\/p>\n<p>\u5176\u4e2d\uff0c\u6b65\u9aa4 1 \u548c 2 \u4e0e\u666e\u901a\u7684 Go \u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u7c7b\u4f3c\uff0c\u9700\u8981\u4f7f\u7528 Go \u7684\u7f16\u8bd1\u5668\u548c\u4f9d\u8d56\u7ba1\u7406\u5de5\u5177\u6765\u5b8c\u6210\u3002\u6b65\u9aa4 3 \u548c 4 \u5219\u662f GoAppEngine \u7279\u6709\u7684\u6253\u5305\u6b65\u9aa4\uff0c\u9700\u8981\u4f7f\u7528\u7279\u5b9a\u7684\u5de5\u5177\u6765\u5b8c\u6210\u3002<\/p>\n<p>\u5728\u751f\u6210 app.yaml \u914d\u7f6e\u6587\u4ef6\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u5e94\u7528\u7a0b\u5e8f\u7684\u8fd0\u884c\u73af\u5883\u3001URL \u6620\u5c04\u89c4\u5219\u3001\u670d\u52a1\u914d\u7f6e\u7b49\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684 app.yaml \u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>runtime: go111<\/p>\n<p>service: my-app<\/p>\n<p>handlers:<\/p>\n<p>&#8211; url: \/.*<\/p>\n<p>  script: auto<\/p>\n<p>&#8220;`<\/p>\n<p>\u8be5\u914d\u7f6e\u6587\u4ef6\u6307\u5b9a\u4e86\u5e94\u7528\u7a0b\u5e8f\u7684\u8fd0\u884c\u73af\u5883\u4e3a Go 1.11\uff0c\u670d\u52a1\u540d\u79f0\u4e3a my-app\uff0cURL \u6620\u5c04\u89c4\u5219\u4e3a\u6240\u6709\u8bf7\u6c42\u90fd\u4ea4\u7531\u5e94\u7528\u7a0b\u5e8f\u5904\u7406\u3002<\/p>\n<p>\u6700\u540e\uff0c\u5c06\u6240\u6709\u6587\u4ef6\u6253\u5305\u6210 ZIP \u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u4e3a\u5e94\u7528\u7a0b\u5e8f\u7684\u670d\u52a1\u540d\u79f0\uff0c\u4f8b\u5982 my-app.zip\u3002\u6253\u5305\u540e\u7684\u6587\u4ef6\u53ef\u4ee5\u76f4\u63a5\u4e0a\u4f20\u5230 Google App Engine \u5e73\u53f0\u8fdb\u884c\u90e8<a href=\"https:\/\/appdabao.yimenapp.com\/jiage-1442.html\">\u5e38\u7528\u8f6f\u4ef6\u6253\u5305\u5c01\u88c5\u5de5\u5177<\/a>\u7f72\u3002<\/p>\n<p>## \u6253\u5305\u64cd\u4f5c\u6d41\u7a0b<\/p>\n<p>\u4e0b\u9762\u4ecb\u7ecd GoAppEngine \u7684\u6253\u5305\u64cd\u4f5c\u6d41\u7a0b\u3002<\/p>\n<p>### 1. \u5b89\u88c5 GoAppEngine SDK<\/p>\n<p>\u9996\u5148\u9700\u8981\u5b89\u88c5 GoAppEngine SDK\uff0c\u53ef\u4ee5\u4ece\u5b98\u7f51\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684 SDK\uff0c\u4e0b\u8f7d\u5730\u5740\u4e3a https:\/\/cloud.googl<a href=\"https:\/\/appdabao.yimenapp.com\/jiage-1045.html\">\u7f51\u7ad9\u4e00\u952e\u751f\u6210app<\/a>e.com\/appengine\/docs\/standard\/go\/download\u3002<\/p>\n<p>\u4e0b\u8f7d\u540e\uff0c\u89e3\u538b\u7f29\u6587\u4ef6\u5e76\u5c06\u89e3\u538b\u540e\u7684\u76ee\u5f55\u6dfb\u52a0\u5230\u7cfb\u7edf PATH \u73af\u5883\u53d8\u91cf\u4e2d\u3002\u4f8b\u5982\uff0c\u5728 Linux \u7cfb\u7edf\u4e2d\u53ef\u4ee5\u5c06\u4ee5\u4e0b\u547d\u4ee4\u6dfb\u52a0\u5230 .bashrc \u6587\u4ef6\u4e2d\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>export PATH=$PATH:\/path\/to\/goappengine\/sdk<\/p>\n<p>&#8220;`<\/p>\n<p>### 2. \u7f16\u8bd1\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u4f7f\u7528 Go \u7684\u7f16\u8bd1\u5668\u5c06\u5e94\u7528\u7a0b\u5e8f\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>$ go build -o my-app main.go<\/p>\n<p>&#8220;`<\/p>\n<p>### 3. \u590d\u5236\u4f9d\u8d56\u5e93<\/p>\n<p>\u5c06\u5e94\u7528\u7a0b\u5e8f\u6240\u4f9d\u8d56\u7684\u5e93\u6587\u4ef6\u590d\u5236\u5230\u6307\u5b9a\u76ee\u5f55\u3002\u53ef\u4ee5\u4f7f\u7528 govendor \u7b49\u4f9d\u8d56\u7ba1\u7406\u5de5\u5177\u6765\u5b8c\u6210\u8be5\u6b65\u9aa4\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>$ govendor sync<\/p>\n<p>$ cp -r vendor\/ \/path\/to\/goappengine\/sdk\/gopath\/<\/p>\n<p>&#8220;`<\/p>\n<p>### 4. \u751f\u6210\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>\u751f\u6210\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u6587\u4ef6 app.yaml\u3002\u53ef\u4ee5\u624b\u52a8\u521b\u5efa\u8be5\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 goapp \u5de5\u5177\u81ea\u52a8\u751f\u6210\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>$ goapp genap<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/21\/15\/03252791575.jpg\" \/><\/figure>\n<\/p>\n<p>p -o app.yaml<\/p>\n<p>&#8220;`<\/p>\n<p>### 5. \u538b\u7f29\u6587\u4ef6<\/p>\n<p>\u5c06\u6240\u6709\u6587\u4ef6\u6253\u5305\u6210 ZIP \u6587\u4ef6\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b8c\u6210\u8be5\u6b65\u9aa4\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>$ zip -r my-app.zip my-app app.yaml vendor<\/p>\n<p>&#8220;`<\/p>\n<p>\u5176\u4e2d\uff0cmy-app \u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0capp.yaml \u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u6587\u4ef6\uff0cvendor \u662f\u5e94\u7528\u7a0b\u5e8f\u6240\u4f9d\u8d56\u7684\u5e93\u6587\u4ef6\u3002<\/p>\n<p>### 6. \u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u6253\u5305\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5c06 ZIP \u6587\u4ef6\u4e0a\u4f20\u5230 Google App Engine \u5e73\u53f0\u8fdb\u884c\u90e8\u7f72\u3002\u53ef\u4ee5\u4f7f\u7528 gcloud \u547d\u4ee4\u884c\u5de5\u5177\u6216\u8005 Google Cloud Console \u8fdb\u884c\u90e8\u7f72\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 gcloud \u5de5\u5177\u8fdb\u884c\u90e8\u7f72\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>$ gcloud app deploy my-app.zip<\/p>\n<p>&#8220;`<\/p>\n<p>\u90e8\u7f72\u5b8c\u6210\u540e\uff0c\u5e94\u7528\u7a0b\u5e8f\u5c31\u53ef\u4ee5\u5728 Google App Engine \u5e73\u53f0\u4e0a\u8fd0\u884c\u4e86\u3002<\/p>\n<p>## \u603b\u7ed3<\/p>\n<p>GoAppEngine \u7684\u6253\u5305\u8fc7\u7a0b\u6bd4\u8f83\u590d\u6742\uff0c\u9700\u8981\u8fdb\u884c\u591a\u4e2a\u6b65\u9aa4\uff0c\u4f46\u662f\u6253\u5305\u540e\u7684\u6587\u4ef6\u53ef\u4ee5\u76f4\u63a5\u4e0a\u4f20\u5230 Google App Engine \u5e73\u53f0\u8fdb\u884c\u90e8\u7f72\uff0c\u65b9\u4fbf\u5feb\u6377\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6253\u5305\u65f6\u9700\u8981\u5c06\u6240\u6709\u4f9d\u8d56\u5e93\u4e00\u5e76\u6253\u5305\uff0c\u5426\u5219\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u65e0\u6cd5\u6b63\u786e\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GoAppEngine \u662f Google App Engine \u7684 Go \u8bed\u8a00\u7248\u672c\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4f7f\u7528 Go \u8bed\u8a00\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u5e76\u90e8\u7f72\u5230 Google App Engine \u5e73\u53f0\u4e0a\u3002GoAppEngin<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[12061,11,81,3855,1323],"topic":[],"class_list":{"0":"post-6668","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-sjapp","7":"tag-app","8":"tag-11","9":"tag-81","11":"tag-1323"},"_links":{"self":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/6668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/comments?post=6668"}],"version-history":[{"count":0,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/6668\/revisions"}],"wp:attachment":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/media?parent=6668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/categories?post=6668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/tags?post=6668"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/topic?post=6668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}