增加Map的包装类型
This commit is contained in:
parent
803cf00bd1
commit
b92b8dbf25
3
go.mod
3
go.mod
@ -2,9 +2,10 @@ module git.zhangdeman.cn/zhangdeman/wrapper
|
||||
|
||||
go 1.20
|
||||
|
||||
require git.zhangdeman.cn/zhangdeman/util v0.0.0-20230801092344-773ac512f305
|
||||
require git.zhangdeman.cn/zhangdeman/util v0.0.0-20230810063945-842592611562
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20230307094841-e437ba87af10 // indirect
|
||||
github.com/BurntSushi/toml v1.3.2 // indirect
|
||||
github.com/Jeffail/gabs v1.4.0 // indirect
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect
|
||||
|
5
go.sum
5
go.sum
@ -1,5 +1,9 @@
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20230307094841-e437ba87af10 h1:+Lg4vXFEiWVKjhUJdXuoP0AgjGT49oqJ3301STnZErk=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20230307094841-e437ba87af10/go.mod h1:+Lc0zYF8sylRi75A7NGmObrLxugwAZa8WVpWh2eh5X0=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230801092344-773ac512f305 h1:6Bs/cQP+eKABHB/01uHQI15PwKbo7n8HNx7nIFUGBp0=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230801092344-773ac512f305/go.mod h1:trYFOShINaQBvinQrH4A0G2kfL22Y2lygEcAiGDt/sc=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230810063945-842592611562 h1:wo0r4mexqkPzQ1SZOw5z8A7FJ3ne1G6A/qWR3iaqlhw=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230810063945-842592611562/go.mod h1:trYFOShINaQBvinQrH4A0G2kfL22Y2lygEcAiGDt/sc=
|
||||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
||||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo=
|
||||
@ -7,6 +11,7 @@ github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbYd8tQGRWacE9kU=
|
||||
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1/go.mod h1:+hnT3ywWDTAFrW5aE+u2Sa/wT555ZqwoCS+pk3p6ry4=
|
||||
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
||||
|
51
map.go
Normal file
51
map.go
Normal file
@ -0,0 +1,51 @@
|
||||
// Package wrapper ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-08-10 15:01
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.zhangdeman.cn/zhangdeman/easymap"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// EasyMap ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:02 2023/8/10
|
||||
func EasyMap(mapData interface{}) Map {
|
||||
m, _ := EasyMapWithError(mapData)
|
||||
return m
|
||||
}
|
||||
|
||||
// EasyMapWithError 转换map,并带上转换的异常
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:06 2023/8/10
|
||||
func EasyMapWithError(mapData interface{}) (Map, error) {
|
||||
m := easymap.NewNormal(true)
|
||||
reflectType := reflect.TypeOf(mapData)
|
||||
if reflectType.Kind() != reflect.Map {
|
||||
return m, errors.New("input data type is " + reflectType.String() + ", not map")
|
||||
}
|
||||
|
||||
reflectValue := reflect.ValueOf(mapData).MapRange()
|
||||
for reflectValue.Next() {
|
||||
// 循环提取相关值
|
||||
m.Set(reflectValue.Key().Interface(), reflectValue.Value().Interface())
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Map ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:14 2023/8/10
|
||||
type Map easymap.EasyMap
|
Loading…
Reference in New Issue
Block a user