Hertz (CloudWeGo) Go
/pixel.gif へのリクエストに空の GIF を返す、Hertz (CloudWeGo) 用の Go スニペット。GIF は起動時に一度だけデコードします。
Hertz (CloudWeGo) Go
package main
import (
"context"
"encoding/base64"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/protocol/consts"
)
var gif, _ = base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
func main() {
h := server.Default(server.WithHostPorts(":8080"))
h.GET("/pixel.gif", func(ctx context.Context, c *app.RequestContext) {
c.Header("Cache-Control", "no-store")
c.Data(consts.StatusOK, "image/gif", gif)
})
h.Spin()
}
このスニペットは実行し、返されたバイト列を照合しました。
確認
curl -sI http://localhost:8080/pixel.gif