emptygif
Basa: Basa Jawa

Kabeh basa lan framework

Hertz (CloudWeGo) Go

Snippet Go kanggo Hertz (CloudWeGo) sing mangsuli request menyang /pixel.gif nganggo empty GIF, sing didekode sepisan nalika startup.

Hertz (CloudWeGo) Go

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

Snippet iki wis dilakokake lan byte asile wis dibandhingake.

Priksa

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

Situs resmi: Hertz (CloudWeGo)

Liyane ing Go