emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

Hertz (CloudWeGo) Go

Ein Go-Snippet für Hertz (CloudWeGo), das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.

Hertz (CloudWeGo) Go

Installieren
go get github.com/cloudwego/hertz
Datei
main.go
Ausführen
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()
}

Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.

Prüfen

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

Offizielle Website: Hertz (CloudWeGo)

Mehr in Go