அனைத்து மொழிகளும் ஃப்ரேம்வொர்க்குகளும்
Huma Go
/pixel.gif க்கு வரும் ரெக்வெஸ்ட்களுக்கு empty GIF மூலம் பதிலளிக்கும், Huma க்கான Go ஸ்னிப்பெட். GIF ஸ்டார்ட்அப்பில் ஒருமுறை மட்டுமே டீகோட் செய்யப்படுகிறது.
Huma Go
package main
import (
"context"
"encoding/base64"
"log"
"net/http"
"github.com/danielgtaylor/huma/v2"
"github.com/danielgtaylor/huma/v2/adapters/humago"
)
var gif, _ = base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
// A []byte Body is sent as-is; tagged fields become response headers.
type PixelOutput struct {
ContentType string `header:"Content-Type"`
CacheControl string `header:"Cache-Control"`
Body []byte
}
func main() {
mux := http.NewServeMux()
api := humago.New(mux, huma.DefaultConfig("Pixel API", "1.0.0"))
huma.Get(api, "/pixel.gif", func(ctx context.Context, _ *struct{}) (*PixelOutput, error) {
return &PixelOutput{ContentType: "image/gif", CacheControl: "no-store", Body: gif}, nil
})
log.Fatal(http.ListenAndServe(":8080", mux))
}
இந்த ஸ்னிப்பெட்டை ரன் செய்து, அது திருப்பித் தந்த பைட்களை ஒப்பிட்டுப் பார்த்தோம்.
சரிபார்
curl -sI http://localhost:8080/pixel.gif