1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tool.go 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-08-27 00:23 +08:00 . feat: rebuild response
package resp
import (
"encoding/json"
"encoding/xml"
"gitee.com/kristas/booting-go/framework/common/util/lang"
"gitee.com/kristas/booting-go/framework/common/util/list"
"gitee.com/kristas/booting-go/framework/core/configure"
"gitee.com/kristas/booting-go/framework/web"
"gopkg.in/yaml.v3"
)
func ContentType(cType string) string {
conf := new(web.Configure)
configure.BindConfiguration(conf)
if !lang.NewString(cType).Contains("charset") && shouldAppendCharset(cType) {
return cType + "; charset=" + conf.Charset
}
return cType
}
func shouldAppendCharset(cType string) bool {
return !list.NewSets(ContentBinaryHeaderValue, ContentWebassemblyHeaderValue, ContentRedirect).
Exists(cType)
//return cType != ContentBinaryHeaderValue &&
// cType != ContentWebassemblyHeaderValue &&
// cType != ContentRedirect
}
var JsonMarshaller Marshaller = func(data interface{}) []byte {
bytes, _ := json.Marshal(data)
return bytes
}
var YamlMarshaller Marshaller = func(data interface{}) []byte {
files, _ := yaml.Marshal(data)
return files
}
var XmlMarshaller Marshaller = func(data interface{}) []byte {
files, _ := xml.Marshal(data)
return files
}
var RawMarshaller Marshaller = func(data interface{}) []byte {
files := lang.NewString(data).GetBytes()
return files
}
var autoMarshaller = map[string]Marshaller{
ContentJSONHeaderValue: JsonMarshaller,
ContentXMLHeaderValue: XmlMarshaller,
ContentYAMLHeaderValue: YamlMarshaller,
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.4.4

搜索帮助