emptygif
언어: 한국어

모든 언어 및 프레임워크

fasthttp Go

/pixel.gif 요청에 빈 GIF로 응답하는 fasthttp용 Go 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.

fasthttp Go

설치
go get github.com/valyala/fasthttp
파일
main.go
실행
go run .
package main

import (
	"encoding/base64"
	"log"

	"github.com/valyala/fasthttp"
)

var gif, _ = base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

func handler(ctx *fasthttp.RequestCtx) {
	if !ctx.IsGet() || string(ctx.Path()) != "/pixel.gif" {
		ctx.NotFound()
		return
	}
	ctx.SetContentType("image/gif")
	ctx.Response.Header.Set("Cache-Control", "no-store")
	ctx.SetBody(gif)
}

func main() {
	log.Fatal(fasthttp.ListenAndServe(":8080", handler))
}

이 스니펫은 실행해 보고, 반환된 바이트를 비교했습니다.

확인

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

공식 사이트: fasthttp

Go의 다른 예제