Encore.go (raw endpoint) Go
/pixel.gif 요청에 빈 GIF로 응답하는 Encore.go (raw endpoint)용 Go 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.
Encore.go (raw endpoint) Go
// pixel/pixel.go: a package with an //encore:api endpoint is an Encore service.
package pixel
import (
"encoding/base64"
"net/http"
)
var gif, _ = base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
// Raw endpoints get the plain http.ResponseWriter.
//
//encore:api public raw method=GET path=/pixel.gif
func Pixel(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "image/gif")
w.Header().Set("Cache-Control", "no-store")
w.Write(gif)
}
이 스니펫은 실행해 보고, 반환된 바이트를 비교했습니다.
확인
curl -sI http://localhost:8080/pixel.gif
공식 사이트: Encore.go (raw endpoint)