emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Hertz (CloudWeGo) Go

Snippet Go untuk Hertz (CloudWeGo) yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Hertz (CloudWeGo) Go

Instal
go get github.com/cloudwego/hertz
File
main.go
Jalankan
go run .
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()
}

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: Hertz (CloudWeGo)

Lainnya dalam Go