mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
rename MapStruct* functions to MapToMap* for gconv and according packags
This commit is contained in:
@ -249,26 +249,26 @@ func (v *Var) StructsDeep(pointer interface{}, mapping ...map[string]string) (er
|
||||
return gconv.StructsDeep(v.Val(), pointer, mapping...)
|
||||
}
|
||||
|
||||
// MapStruct converts map type variable <params> to another map type variable <pointer>.
|
||||
// MapToMap converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of struct/*struct.
|
||||
func (v *Var) MapStruct(pointer interface{}, mapping ...map[string]string) (err error) {
|
||||
return gconv.MapStruct(v.Val(), pointer, mapping...)
|
||||
func (v *Var) MapToMap(pointer interface{}, mapping ...map[string]string) (err error) {
|
||||
return gconv.MapToMap(v.Val(), pointer, mapping...)
|
||||
}
|
||||
|
||||
// MapStructDeep recursively converts map type variable <params> to another map type variable <pointer>.
|
||||
// MapToMapDeep recursively converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of struct/*struct.
|
||||
func (v *Var) MapStructDeep(pointer interface{}, mapping ...map[string]string) (err error) {
|
||||
return gconv.MapStructDeep(v.Val(), pointer, mapping...)
|
||||
func (v *Var) MapToMapDeep(pointer interface{}, mapping ...map[string]string) (err error) {
|
||||
return gconv.MapToMapDeep(v.Val(), pointer, mapping...)
|
||||
}
|
||||
|
||||
// MapStructs converts map type variable <params> to another map type variable <pointer>.
|
||||
// MapToMaps converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of []struct/[]*struct.
|
||||
func (v *Var) MapStructs(pointer interface{}, mapping ...map[string]string) (err error) {
|
||||
return gconv.MapStructs(v.Val(), pointer, mapping...)
|
||||
func (v *Var) MapToMaps(pointer interface{}, mapping ...map[string]string) (err error) {
|
||||
return gconv.MapToMaps(v.Val(), pointer, mapping...)
|
||||
}
|
||||
|
||||
// MapStructsDeep recursively converts map type variable <params> to another map type variable <pointer>.
|
||||
// MapToMapsDeep recursively converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of []struct/[]*struct.
|
||||
func (v *Var) MapStructsDeep(pointer interface{}, mapping ...map[string]string) (err error) {
|
||||
return gconv.MapStructsDeep(v.Val(), pointer, mapping...)
|
||||
func (v *Var) MapToMapsDeep(pointer interface{}, mapping ...map[string]string) (err error) {
|
||||
return gconv.MapToMapsDeep(v.Val(), pointer, mapping...)
|
||||
}
|
||||
|
||||
@ -296,20 +296,20 @@ func (j *Json) GetStructsDeep(pattern string, pointer interface{}, mapping ...ma
|
||||
return gconv.StructsDeep(j.Get(pattern), pointer, mapping...)
|
||||
}
|
||||
|
||||
func (j *Json) GetMapStruct(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
return gconv.MapStruct(j.Get(pattern), pointer, mapping...)
|
||||
func (j *Json) GetMapToMap(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
return gconv.MapToMap(j.Get(pattern), pointer, mapping...)
|
||||
}
|
||||
|
||||
func (j *Json) GetMapStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
return gconv.MapStructDeep(j.Get(pattern), pointer, mapping...)
|
||||
func (j *Json) GetMapToMapDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
return gconv.MapToMapDeep(j.Get(pattern), pointer, mapping...)
|
||||
}
|
||||
|
||||
func (j *Json) GetMapStructs(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
return gconv.MapStructs(j.Get(pattern), pointer, mapping...)
|
||||
func (j *Json) GetMapToMaps(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
return gconv.MapToMaps(j.Get(pattern), pointer, mapping...)
|
||||
}
|
||||
|
||||
func (j *Json) GetMapStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
return gconv.MapStructsDeep(j.Get(pattern), pointer, mapping...)
|
||||
func (j *Json) GetMapToMapsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
return gconv.MapToMapsDeep(j.Get(pattern), pointer, mapping...)
|
||||
}
|
||||
|
||||
// ToMap converts current Json object to map[string]interface{}.
|
||||
@ -354,28 +354,28 @@ func (j *Json) ToStructsDeep(pointer interface{}, mapping ...map[string]string)
|
||||
return gconv.StructsDeep(*(j.p), pointer, mapping...)
|
||||
}
|
||||
|
||||
func (j *Json) ToMapStruct(pointer interface{}, mapping ...map[string]string) error {
|
||||
func (j *Json) ToMapToMap(pointer interface{}, mapping ...map[string]string) error {
|
||||
j.mu.RLock()
|
||||
defer j.mu.RUnlock()
|
||||
return gconv.MapStruct(*(j.p), pointer, mapping...)
|
||||
return gconv.MapToMap(*(j.p), pointer, mapping...)
|
||||
}
|
||||
|
||||
func (j *Json) ToMapStructDeep(pointer interface{}, mapping ...map[string]string) error {
|
||||
func (j *Json) ToMapToMapDeep(pointer interface{}, mapping ...map[string]string) error {
|
||||
j.mu.RLock()
|
||||
defer j.mu.RUnlock()
|
||||
return gconv.MapStructDeep(*(j.p), pointer, mapping...)
|
||||
return gconv.MapToMapDeep(*(j.p), pointer, mapping...)
|
||||
}
|
||||
|
||||
func (j *Json) ToMapStructs(pointer interface{}, mapping ...map[string]string) error {
|
||||
func (j *Json) ToMapToMaps(pointer interface{}, mapping ...map[string]string) error {
|
||||
j.mu.RLock()
|
||||
defer j.mu.RUnlock()
|
||||
return gconv.MapStructs(*(j.p), pointer, mapping...)
|
||||
return gconv.MapToMaps(*(j.p), pointer, mapping...)
|
||||
}
|
||||
|
||||
func (j *Json) ToMapStructsDeep(pointer interface{}, mapping ...map[string]string) error {
|
||||
func (j *Json) ToMapToMapsDeep(pointer interface{}, mapping ...map[string]string) error {
|
||||
j.mu.RLock()
|
||||
defer j.mu.RUnlock()
|
||||
return gconv.MapStructsDeep(*(j.p), pointer, mapping...)
|
||||
return gconv.MapToMapsDeep(*(j.p), pointer, mapping...)
|
||||
}
|
||||
|
||||
// Dump prints current Json object with more manually readable.
|
||||
|
||||
@ -160,6 +160,10 @@ func (r *Request) GetMap(def ...map[string]interface{}) map[string]interface{} {
|
||||
return r.GetRequestMap(def...)
|
||||
}
|
||||
|
||||
func (r *Request) GetMapStrStr(def ...map[string]interface{}) map[string]string {
|
||||
return r.GetRequestMapStrStr(def...)
|
||||
}
|
||||
|
||||
// 将所有的request参数映射到struct属性上,参数pointer应当为一个struct对象的指针,
|
||||
// mapping为非必需参数,自定义参数与属性的映射关系
|
||||
func (r *Request) GetToStruct(pointer interface{}, mapping ...map[string]string) error {
|
||||
|
||||
@ -145,6 +145,18 @@ func (r *Request) GetPostMap(kvMap ...map[string]interface{}) map[string]interfa
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Request) GetPostMapStrStr(kvMap ...map[string]interface{}) map[string]string {
|
||||
postMap := r.GetPostMap(kvMap...)
|
||||
if len(postMap) > 0 {
|
||||
m := make(map[string]string)
|
||||
for k, v := range postMap {
|
||||
m[k] = gconv.String(v)
|
||||
}
|
||||
return m
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 将所有的request参数映射到struct属性上,参数object应当为一个struct对象的指针, mapping为非必需参数,自定义参数与属性的映射关系
|
||||
func (r *Request) GetPostToStruct(pointer interface{}, mapping ...map[string]string) error {
|
||||
r.initPost()
|
||||
|
||||
@ -117,6 +117,18 @@ func (r *Request) GetQueryMap(kvMap ...map[string]interface{}) map[string]interf
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Request) GetQueryMapStrStr(kvMap ...map[string]interface{}) map[string]string {
|
||||
queryMap := r.GetQueryMap(kvMap...)
|
||||
if len(queryMap) > 0 {
|
||||
m := make(map[string]string)
|
||||
for k, v := range queryMap {
|
||||
m[k] = gconv.String(v)
|
||||
}
|
||||
return m
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 将所有的get参数映射到struct属性上,参数object应当为一个struct对象的指针, mapping为非必需参数,自定义参数与属性的映射关系
|
||||
func (r *Request) GetQueryToStruct(pointer interface{}, mapping ...map[string]string) error {
|
||||
r.initGet()
|
||||
|
||||
@ -118,6 +118,18 @@ func (r *Request) GetRequestMap(kvMap ...map[string]interface{}) map[string]inte
|
||||
return m
|
||||
}
|
||||
|
||||
func (r *Request) GetRequestMapStrStr(kvMap ...map[string]interface{}) map[string]string {
|
||||
requestMap := r.GetRequestMap(kvMap...)
|
||||
if len(requestMap) > 0 {
|
||||
m := make(map[string]string)
|
||||
for k, v := range requestMap {
|
||||
m[k] = gconv.String(v)
|
||||
}
|
||||
return m
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 将所有的request参数映射到struct属性上,参数object应当为一个struct对象的指针, mapping为非必需参数,自定义参数与属性的映射关系
|
||||
func (r *Request) GetRequestToStruct(pointer interface{}, mapping ...map[string]string) error {
|
||||
tagMap := structs.TagMapName(pointer, paramTagPriority, true)
|
||||
|
||||
@ -50,6 +50,12 @@ func Test_Params_Basic(t *testing.T) {
|
||||
if r.GetQuery("string") != nil {
|
||||
r.Response.Write(r.GetQueryString("string"))
|
||||
}
|
||||
if r.GetQuery("map") != nil {
|
||||
r.Response.Write(r.GetQueryMap()["map"].(map[string]interface{})["b"])
|
||||
}
|
||||
if r.GetQuery("a") != nil {
|
||||
r.Response.Write(r.GetQueryMapStrStr()["a"])
|
||||
}
|
||||
})
|
||||
s.BindHandler("/put", func(r *ghttp.Request) {
|
||||
if r.Get("array") != nil {
|
||||
@ -79,6 +85,9 @@ func Test_Params_Basic(t *testing.T) {
|
||||
if r.Get("map") != nil {
|
||||
r.Response.Write(r.GetMap()["map"].(map[string]interface{})["b"])
|
||||
}
|
||||
if r.Get("a") != nil {
|
||||
r.Response.Write(r.GetMapStrStr()["a"])
|
||||
}
|
||||
})
|
||||
s.BindHandler("/post", func(r *ghttp.Request) {
|
||||
if r.GetPost("array") != nil {
|
||||
@ -108,6 +117,9 @@ func Test_Params_Basic(t *testing.T) {
|
||||
if r.GetPost("map") != nil {
|
||||
r.Response.Write(r.GetPostMap()["map"].(map[string]interface{})["b"])
|
||||
}
|
||||
if r.GetPost("a") != nil {
|
||||
r.Response.Write(r.GetPostMapStrStr()["a"])
|
||||
}
|
||||
})
|
||||
s.BindHandler("/map", func(r *ghttp.Request) {
|
||||
if m := r.GetQueryMap(); len(m) > 0 {
|
||||
@ -181,6 +193,8 @@ func Test_Params_Basic(t *testing.T) {
|
||||
gtest.Assert(client.GetContent("/get", "uint=10000"), `10000`)
|
||||
gtest.Assert(client.GetContent("/get", "uint=9"), `9`)
|
||||
gtest.Assert(client.GetContent("/get", "string=key"), `key`)
|
||||
gtest.Assert(client.GetContent("/get", "map[a]=1&map[b]=2"), `2`)
|
||||
gtest.Assert(client.GetContent("/get", "a=1&b=2"), `1`)
|
||||
|
||||
// PUT
|
||||
gtest.Assert(client.PutContent("/put", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
@ -195,6 +209,7 @@ func Test_Params_Basic(t *testing.T) {
|
||||
gtest.Assert(client.PutContent("/put", "uint=9"), `9`)
|
||||
gtest.Assert(client.PutContent("/put", "string=key"), `key`)
|
||||
gtest.Assert(client.PutContent("/put", "map[a]=1&map[b]=2"), `2`)
|
||||
gtest.Assert(client.PutContent("/put", "a=1&b=2"), `1`)
|
||||
|
||||
// POST
|
||||
gtest.Assert(client.PostContent("/post", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
@ -209,6 +224,7 @@ func Test_Params_Basic(t *testing.T) {
|
||||
gtest.Assert(client.PostContent("/post", "uint=9"), `9`)
|
||||
gtest.Assert(client.PostContent("/post", "string=key"), `key`)
|
||||
gtest.Assert(client.PostContent("/post", "map[a]=1&map[b]=2"), `2`)
|
||||
gtest.Assert(client.PostContent("/post", "a=1&b=2"), `1`)
|
||||
|
||||
// Map
|
||||
gtest.Assert(client.GetContent("/map", "id=1&name=john"), `john`)
|
||||
|
||||
@ -254,30 +254,30 @@ func (c *Config) GetStructsDeep(pattern string, pointer interface{}, mapping ...
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
|
||||
func (c *Config) GetMapStruct(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
func (c *Config) GetMapToMap(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.GetMapStruct(pattern, pointer, mapping...)
|
||||
return j.GetMapToMap(pattern, pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
|
||||
func (c *Config) GetMapStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
func (c *Config) GetMapToMapDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.GetMapStructDeep(pattern, pointer, mapping...)
|
||||
return j.GetMapToMapDeep(pattern, pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
|
||||
func (c *Config) GetMapStructs(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
func (c *Config) GetMapToMaps(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.GetMapStructs(pattern, pointer, mapping...)
|
||||
return j.GetMapToMaps(pattern, pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
|
||||
func (c *Config) GetMapStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
func (c *Config) GetMapToMapsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.GetMapStructsDeep(pattern, pointer, mapping...)
|
||||
return j.GetMapToMapsDeep(pattern, pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
@ -324,30 +324,30 @@ func (c *Config) ToStructsDeep(pointer interface{}, mapping ...map[string]string
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
|
||||
func (c *Config) ToMapStruct(pointer interface{}, mapping ...map[string]string) error {
|
||||
func (c *Config) ToMapToMap(pointer interface{}, mapping ...map[string]string) error {
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.ToMapStruct(pointer, mapping...)
|
||||
return j.ToMapToMap(pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
|
||||
func (c *Config) ToMapStructDeep(pointer interface{}, mapping ...map[string]string) error {
|
||||
func (c *Config) ToMapToMapDeep(pointer interface{}, mapping ...map[string]string) error {
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.ToMapStructDeep(pointer, mapping...)
|
||||
return j.ToMapToMapDeep(pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
|
||||
func (c *Config) ToMapStructs(pointer interface{}, mapping ...map[string]string) error {
|
||||
func (c *Config) ToMapToMaps(pointer interface{}, mapping ...map[string]string) error {
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.ToMapStructs(pointer, mapping...)
|
||||
return j.ToMapToMaps(pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
|
||||
func (c *Config) ToMapStructsDeep(pointer interface{}, mapping ...map[string]string) error {
|
||||
func (c *Config) ToMapToMapsDeep(pointer interface{}, mapping ...map[string]string) error {
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.ToMapStructsDeep(pointer, mapping...)
|
||||
return j.ToMapToMapsDeep(pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
}
|
||||
|
||||
@ -181,21 +181,21 @@ func MapDeep(value interface{}, tags ...string) map[string]interface{} {
|
||||
return data
|
||||
}
|
||||
|
||||
// MapStruct converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of struct/*struct.
|
||||
func MapStruct(params interface{}, pointer interface{}, mapping ...map[string]string) error {
|
||||
return doMapStruct(params, pointer, false, mapping...)
|
||||
// MapToMap converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of *map.
|
||||
func MapToMap(params interface{}, pointer interface{}, mapping ...map[string]string) error {
|
||||
return doMapToMap(params, pointer, false, mapping...)
|
||||
}
|
||||
|
||||
// MapStructDeep recursively converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of struct/*struct.
|
||||
func MapStructDeep(params interface{}, pointer interface{}, mapping ...map[string]string) error {
|
||||
return doMapStruct(params, pointer, true, mapping...)
|
||||
// MapToMapDeep recursively converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of *map.
|
||||
func MapToMapDeep(params interface{}, pointer interface{}, mapping ...map[string]string) error {
|
||||
return doMapToMap(params, pointer, true, mapping...)
|
||||
}
|
||||
|
||||
// doMapStruct converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of struct/*struct.
|
||||
func doMapStruct(params interface{}, pointer interface{}, deep bool, mapping ...map[string]string) error {
|
||||
// The elements of <pointer> should be type of *map.
|
||||
func doMapToMap(params interface{}, pointer interface{}, deep bool, mapping ...map[string]string) error {
|
||||
paramsRv := reflect.ValueOf(params)
|
||||
paramsKind := paramsRv.Kind()
|
||||
if paramsKind == reflect.Ptr {
|
||||
@ -240,21 +240,21 @@ func doMapStruct(params interface{}, pointer interface{}, deep bool, mapping ...
|
||||
return nil
|
||||
}
|
||||
|
||||
// MapStructs converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of []struct/[]*struct.
|
||||
func MapStructs(params interface{}, pointer interface{}, mapping ...map[string]string) error {
|
||||
return doMapStructs(params, pointer, false, mapping...)
|
||||
// MapToMaps converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of []map/*map.
|
||||
func MapToMaps(params interface{}, pointer interface{}, mapping ...map[string]string) error {
|
||||
return doMapToMaps(params, pointer, false, mapping...)
|
||||
}
|
||||
|
||||
// MapStructsDeep recursively converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of []struct/[]*struct.
|
||||
func MapStructsDeep(params interface{}, pointer interface{}, mapping ...map[string]string) error {
|
||||
return doMapStructs(params, pointer, true, mapping...)
|
||||
// MapToMapsDeep recursively converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of []map/*map.
|
||||
func MapToMapsDeep(params interface{}, pointer interface{}, mapping ...map[string]string) error {
|
||||
return doMapToMaps(params, pointer, true, mapping...)
|
||||
}
|
||||
|
||||
// doMapStructs converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of []struct/[]*struct.
|
||||
func doMapStructs(params interface{}, pointer interface{}, deep bool, mapping ...map[string]string) error {
|
||||
// doMapToMaps converts map type variable <params> to another map type variable <pointer>.
|
||||
// The elements of <pointer> should be type of []map/*map.
|
||||
func doMapToMaps(params interface{}, pointer interface{}, deep bool, mapping ...map[string]string) error {
|
||||
paramsRv := reflect.ValueOf(params)
|
||||
paramsKind := paramsRv.Kind()
|
||||
if paramsKind == reflect.Ptr {
|
||||
|
||||
@ -161,7 +161,7 @@ func Test_Map_StructInherit(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_MapStruct(t *testing.T) {
|
||||
func Test_MapToMap(t *testing.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Name string
|
||||
@ -174,7 +174,7 @@ func Test_MapStruct(t *testing.T) {
|
||||
}
|
||||
gtest.Case(t, func() {
|
||||
m := make(map[string]User)
|
||||
err := gconv.MapStruct(params, &m)
|
||||
err := gconv.MapToMap(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 1)
|
||||
gtest.Assert(m["key"].Id, 1)
|
||||
@ -182,7 +182,7 @@ func Test_MapStruct(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := (map[string]User)(nil)
|
||||
err := gconv.MapStruct(params, &m)
|
||||
err := gconv.MapToMap(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 1)
|
||||
gtest.Assert(m["key"].Id, 1)
|
||||
@ -190,7 +190,7 @@ func Test_MapStruct(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := make(map[string]*User)
|
||||
err := gconv.MapStruct(params, &m)
|
||||
err := gconv.MapToMap(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 1)
|
||||
gtest.Assert(m["key"].Id, 1)
|
||||
@ -198,7 +198,7 @@ func Test_MapStruct(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := (map[string]*User)(nil)
|
||||
err := gconv.MapStruct(params, &m)
|
||||
err := gconv.MapToMap(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 1)
|
||||
gtest.Assert(m["key"].Id, 1)
|
||||
@ -206,7 +206,7 @@ func Test_MapStruct(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_MapStructDeep(t *testing.T) {
|
||||
func Test_MapToMapDeep(t *testing.T) {
|
||||
type Ids struct {
|
||||
Id int
|
||||
Uid int
|
||||
@ -227,7 +227,7 @@ func Test_MapStructDeep(t *testing.T) {
|
||||
}
|
||||
gtest.Case(t, func() {
|
||||
m := (map[string]*User)(nil)
|
||||
err := gconv.MapStruct(params, &m)
|
||||
err := gconv.MapToMap(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 1)
|
||||
gtest.Assert(m["key"].Id, 0)
|
||||
@ -235,7 +235,7 @@ func Test_MapStructDeep(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := (map[string]*User)(nil)
|
||||
err := gconv.MapStructDeep(params, &m)
|
||||
err := gconv.MapToMapDeep(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 1)
|
||||
gtest.Assert(m["key"].Id, 1)
|
||||
@ -243,7 +243,7 @@ func Test_MapStructDeep(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_MapStructs1(t *testing.T) {
|
||||
func Test_MapToMaps1(t *testing.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Name int
|
||||
@ -260,7 +260,7 @@ func Test_MapStructs1(t *testing.T) {
|
||||
}
|
||||
gtest.Case(t, func() {
|
||||
m := make(map[string][]User)
|
||||
err := gconv.MapStructs(params, &m)
|
||||
err := gconv.MapToMaps(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 2)
|
||||
gtest.Assert(m["key1"][0].Id, 1)
|
||||
@ -270,7 +270,7 @@ func Test_MapStructs1(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := (map[string][]User)(nil)
|
||||
err := gconv.MapStructs(params, &m)
|
||||
err := gconv.MapToMaps(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 2)
|
||||
gtest.Assert(m["key1"][0].Id, 1)
|
||||
@ -280,7 +280,7 @@ func Test_MapStructs1(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := make(map[string][]*User)
|
||||
err := gconv.MapStructs(params, &m)
|
||||
err := gconv.MapToMaps(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 2)
|
||||
gtest.Assert(m["key1"][0].Id, 1)
|
||||
@ -290,7 +290,7 @@ func Test_MapStructs1(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := (map[string][]*User)(nil)
|
||||
err := gconv.MapStructs(params, &m)
|
||||
err := gconv.MapToMaps(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 2)
|
||||
gtest.Assert(m["key1"][0].Id, 1)
|
||||
@ -300,7 +300,7 @@ func Test_MapStructs1(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_MapStructs2(t *testing.T) {
|
||||
func Test_MapToMaps2(t *testing.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Name int
|
||||
@ -317,7 +317,7 @@ func Test_MapStructs2(t *testing.T) {
|
||||
}
|
||||
gtest.Case(t, func() {
|
||||
m := make(map[int][]User)
|
||||
err := gconv.MapStructs(params, &m)
|
||||
err := gconv.MapToMaps(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 2)
|
||||
gtest.Assert(m[100][0].Id, 1)
|
||||
@ -327,7 +327,7 @@ func Test_MapStructs2(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := make(map[int][]*User)
|
||||
err := gconv.MapStructs(params, &m)
|
||||
err := gconv.MapToMaps(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 2)
|
||||
gtest.Assert(m[100][0].Id, 1)
|
||||
@ -337,7 +337,7 @@ func Test_MapStructs2(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := make(map[string][]*User)
|
||||
err := gconv.MapStructs(params, &m)
|
||||
err := gconv.MapToMaps(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 2)
|
||||
gtest.Assert(m["100"][0].Id, 1)
|
||||
@ -347,7 +347,7 @@ func Test_MapStructs2(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_MapStructsDeep(t *testing.T) {
|
||||
func Test_MapToMapsDeep(t *testing.T) {
|
||||
type Ids struct {
|
||||
Id int
|
||||
Uid int
|
||||
@ -372,7 +372,7 @@ func Test_MapStructsDeep(t *testing.T) {
|
||||
}
|
||||
gtest.Case(t, func() {
|
||||
m := make(map[string][]*User)
|
||||
err := gconv.MapStructs(params, &m)
|
||||
err := gconv.MapToMaps(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 2)
|
||||
gtest.Assert(m["100"][0].Id, 0)
|
||||
@ -386,7 +386,7 @@ func Test_MapStructsDeep(t *testing.T) {
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
m := make(map[string][]*User)
|
||||
err := gconv.MapStructsDeep(params, &m)
|
||||
err := gconv.MapToMapsDeep(params, &m)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(m), 2)
|
||||
gtest.Assert(m["100"][0].Id, 1)
|
||||
|
||||
Reference in New Issue
Block a user