mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-25 10:58:18 +08:00
- Move MessagePack, BSON, YAML, TOML and ProtoBuf rendering and binding out of core into github.com/gin-gonic/gin/render/<format> subpackages - Add content-type registries to binding and render that each subpackage populates from init() so ShouldBind and Negotiate keep negotiating - Slim binding.Default to core types and resolve the rest via the registry - Drop the obsolete nomsgpack build tag and binding_nomsgpack.go - Cut a minimal JSON-only binary from 13MB to 6.5MB; non-core codecs now cost binary size only when their subpackage is imported BREAKING CHANGE: c.YAML, c.TOML, c.ProtoBuf, c.BSON, c.BindYAML, c.BindTOML, c.ShouldBindYAML, c.ShouldBindTOML, c.ShouldBindBodyWithYAML and c.ShouldBindBodyWithTOML are removed, along with binding.MsgPack/BSON/YAML/ TOML/ProtoBuf, the render.MsgPack/BSON/YAML/TOML/ProtoBuf types and the nomsgpack build tag. Import the matching github.com/gin-gonic/gin/render/<format> subpackage and use its Render(c, code, obj) / ShouldBind(c, &obj) helpers (or pass <format>.Binding to c.ShouldBindWith). Importing the subpackage also re-registers the content type so c.ShouldBind and c.Negotiate work as before. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
|
// Use of this source code is governed by a MIT style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package render
|
|
|
|
import "net/http"
|
|
|
|
// Render interface is to be implemented by JSON, XML, HTML, YAML and so on.
|
|
type Render interface {
|
|
// Render writes data with custom ContentType.
|
|
Render(http.ResponseWriter) error
|
|
// WriteContentType writes custom ContentType.
|
|
WriteContentType(w http.ResponseWriter)
|
|
}
|
|
|
|
var (
|
|
_ Render = (*JSON)(nil)
|
|
_ Render = (*IndentedJSON)(nil)
|
|
_ Render = (*SecureJSON)(nil)
|
|
_ Render = (*JsonpJSON)(nil)
|
|
_ Render = (*XML)(nil)
|
|
_ Render = (*String)(nil)
|
|
_ Render = (*Redirect)(nil)
|
|
_ Render = (*Data)(nil)
|
|
_ Render = (*HTML)(nil)
|
|
_ HTMLRender = (*HTMLDebug)(nil)
|
|
_ HTMLRender = (*HTMLProduction)(nil)
|
|
_ Render = (*Reader)(nil)
|
|
_ Render = (*AsciiJSON)(nil)
|
|
_ Render = (*PDF)(nil)
|
|
)
|
|
|
|
func writeContentType(w http.ResponseWriter, value []string) {
|
|
header := w.Header()
|
|
if val := header["Content-Type"]; len(val) == 0 {
|
|
header["Content-Type"] = value
|
|
}
|
|
}
|