Go 1.11 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 Go 1.11 應用程式,即使貴機構先前使用機構政策重新啟用舊版執行階段的部署作業也一樣。現有的 Go 1.11 應用程式在
淘汰日期過後,仍會繼續執行並接收流量。建議您
遷移至最新支援的 Go 版本。
Go 工作佇列範例
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本範例會建立一個能顯示 HTML 表單的應用程式。在對話方塊中輸入字串,然後按一下 Add
。應用程式會計算您以這種方式輸入任何字串的次數。
應用程式會執行下列程序:
- 當您按一下
Add
時,表單會使用 HTTP POST
要求,將字串傳送至在 App Engine 上執行的應用程式。此時,應用程式會將字串與工作綁定成套件,再傳送至預設佇列
。
- 佇列會將工作轉送至對應至網址
/worker
的內含工作處理常式,該常式會將字串非同步寫入資料儲存庫。
- 傳送 HTTP
GET
要求會顯示您輸入的字串清單,以及您Add
每個字串的次數 (透過輸入或點選下拉式方塊中的字串)。
將此應用程式部署至 App Engine:
將下列內容複製到名為 queue.yaml
的檔案。這會將工作處理率從每秒 5 件的預設值變更為每秒 3 件。
queue:
- name: default
rate: 3/s
在同一個目錄中,將下列內容複製到您喜歡的檔案名稱 (結尾為 .go
)。這是應用程式程式碼,包括工作處理常式。
在同一個目錄中,將下列內容複製到名為 app.yaml
的檔案。隨即完成在 App Engine 中使用該應用程式的設定:
請確認您的 Google Cloud Platform 專案確實已備妥 App Engine 應用程式,您也已經初始化並設定該專案的 gcloud
指令。
使用 gcloud app deploy
指令將應用程式部署至 App Engine。
使用 gcloud app browse
指令查看應用程式執行情形。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-19 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-19 (世界標準時間)。"],[[["This application counts and displays the number of times a string is entered via an HTML form."],["When a string is added, it's sent to App Engine via an HTTP POST request, bundled into a task, and added to the default queue."],["The task queue forwards the task to a worker handler, which then writes the string to a datastore asynchronously."],["An HTTP GET request retrieves and displays a list of the entered strings and their corresponding counts."],["The application can be deployed to App Engine using specific configuration files and the `gcloud` command-line tool."]]],[]]