gin
gin copied to clipboard
adjusted negotiation logic so that it is possible to add or overwrite…
… 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")
}
resolves: #3799
@kkoehler Please add more testing.
@kkoehler Please add more testing.
@appleboy added some tests to the pull request