emptygif
भाषा: हिन्दी

सभी भाषाएँ और फ़्रेमवर्क

AWS Lambda (Go) Go

AWS Lambda (Go) के लिए Go स्निपेट, जो /pixel.gif पर आने वाली रिक्वेस्ट का जवाब empty GIF से देता है। GIF स्टार्टअप पर एक ही बार डिकोड होता है।

AWS Lambda (Go) Go

इंस्टॉल
go get github.com/aws/aws-lambda-go
फ़ाइल
main.go
// Behind an API Gateway HTTP API route "GET /pixel.gif" (payload format 2.0) or a function URL.
package main

import (
	"context"

	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
)

// Binary bodies travel base64-encoded, so the GIF stays in base64 here.
const gifBase64 = "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="

func handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) {
	return events.APIGatewayV2HTTPResponse{
		StatusCode:      200,
		Headers:         map[string]string{"Content-Type": "image/gif", "Cache-Control": "no-store"},
		Body:            gifBase64,
		IsBase64Encoded: true,
	}, nil
}

func main() {
	lambda.Start(handler)
}

हमने यह स्निपेट चलाया और इसके लौटाए बाइट्स की तुलना की।

जाँचें

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

आधिकारिक साइट: AWS Lambda (Go)

Go में और