6 Star 11 Fork 1

distill/distill-infra

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
json.go 957 Bytes
一键复制 编辑 原始数据 按行查看 历史
Lyndon Hu 提交于 2020-05-03 09:53 . infra toml
package utils
import (
jsoniter "github.com/json-iterator/go"
"github.com/mitchellh/mapstructure"
)
// 定义JSON操作
var (
json = jsoniter.ConfigCompatibleWithStandardLibrary
JSONMarshal = json.Marshal
JSONUnmarshal = json.Unmarshal
JSONMarshalIndent = json.MarshalIndent
JSONNewDecoder = json.NewDecoder
JSONNewEncoder = json.NewEncoder
)
// JSONMarshalToString JSON编码为字符串
func JSONMarshalToString(v interface{}) string {
s, err := jsoniter.MarshalToString(v)
if err != nil {
return ""
}
return s
}
func StructToMap(in interface{}) (map[string]interface{}, error) {
m := make(map[string]interface{})
jsonBytes, err := json.Marshal(in)
if err != nil {
return nil, err
}
err = json.Unmarshal(jsonBytes, &m)
if err != nil {
return nil, err
}
return m, nil
}
func MapToStruct(inMap map[string]interface{}, out interface{}) error {
err := mapstructure.Decode(inMap, out)
return err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/banyanhouse/distill-infra.git
git@gitee.com:banyanhouse/distill-infra.git
banyanhouse
distill-infra
distill-infra
v0.0.7

搜索帮助