gin icon indicating copy to clipboard operation
gin copied to clipboard

adjusted negotiation logic so that it is possible to add or overwrite…

Open kkoehler opened this issue 6 months ago • 3 comments

… render logic for sepcific content-types and added/referenced a default protobuf renderer.

The following code is a sample which shows the handling for ProtoBuf data. The old API is still working.

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"google.golang.org/protobuf/types/known/structpb"
)

func main() {
	g := gin.Default()

	testData, _ := structpb.NewStruct(map[string]interface{}{
		"key": "value",
	})

	negotiate := gin.NewNegotiate([]string{
		binding.MIMEJSON,
		binding.MIMEPROTOBUF,
	})
	g.GET("/negotiate", func(c *gin.Context) {
		c.Negotiate(200, negotiate.WithData(testData))
	})

	g.Run(":8080")
}

kkoehler avatar Jun 24 '25 15:06 kkoehler

resolves: #3799

kkoehler avatar Jun 24 '25 15:06 kkoehler

@kkoehler Please add more testing.

appleboy avatar Jun 26 '25 01:06 appleboy

@kkoehler Please add more testing.

@appleboy added some tests to the pull request

kkoehler avatar Jun 27 '25 07:06 kkoehler