emptygif
語言: 繁體中文

所有語言和框架

Google Cloud Run functions (Python) Python

適用於 Google Cloud Run functions (Python) 的 Python 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

Google Cloud Run functions (Python) Python

安裝
pip install functions-framework
檔案
main.py
執行
functions-framework --target=pixel --port=8080
import base64

import functions_framework

GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")


@functions_framework.http
def pixel(request):
    if request.path != "/pixel.gif":
        return "Not Found", 404
    return GIF, 200, {"Content-Type": "image/gif", "Cache-Control": "no-store"}

我們執行了這段程式碼,並比對了它回傳的位元組。

驗證

curl -sI http://localhost:8080/pixel.gif

官方網站: Google Cloud Run functions (Python)

更多 Python 範例