emptygif
语言: 简体中文

所有语言和框架

Encore.go (raw endpoint) Go

一个用于 Encore.go (raw endpoint) 的 Go 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。

Encore.go (raw endpoint) Go

安装
encore app create --example=hello-world
文件
pixel.go
运行
encore run --port 8080
// 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)

更多 Go 示例