emptygif
Ngôn ngữ: Tiếng Việt

Tất cả ngôn ngữ và framework

Google Cloud Run functions (Python) Python

Đoạn mã Python cho Google Cloud Run functions (Python), trả lời các yêu cầu tới /pixel.gif bằng GIF rỗng, được giải mã một lần khi khởi động.

Google Cloud Run functions (Python) Python

Cài đặt
pip install functions-framework
Tệp
main.py
Chạy
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"}

Chúng tôi đã chạy đoạn mã này và so sánh các byte nó trả về.

Kiểm tra

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

Trang chính thức: Google Cloud Run functions (Python)

Thêm với Python