unify command or enviroment key names for packages

This commit is contained in:
John Guo
2021-06-26 12:08:18 +08:00
parent 025cdd66c5
commit c25f88293b
22 changed files with 93 additions and 263 deletions

View File

@ -319,23 +319,11 @@ func (j *Json) GetStruct(pattern string, pointer interface{}, mapping ...map[str
return gconv.Struct(j.Get(pattern), pointer, mapping...)
}
// GetStructDeep does GetStruct recursively.
// Deprecated, use GetStruct instead.
func (j *Json) GetStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
return gconv.StructDeep(j.Get(pattern), pointer, mapping...)
}
// GetStructs converts any slice to given struct slice.
func (j *Json) GetStructs(pattern string, pointer interface{}, mapping ...map[string]string) error {
return gconv.Structs(j.Get(pattern), pointer, mapping...)
}
// GetStructsDeep converts any slice to given struct slice recursively.
// Deprecated, use GetStructs instead.
func (j *Json) GetStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error {
return gconv.StructsDeep(j.Get(pattern), pointer, mapping...)
}
// GetScan automatically calls Struct or Structs function according to the type of parameter
// <pointer> to implement the converting..
func (j *Json) GetScan(pattern string, pointer interface{}, mapping ...map[string]string) error {

View File

@ -70,7 +70,7 @@ func (j *Json) MustToJsonIndentString() string {
// ========================================================================
func (j *Json) ToXml(rootTag ...string) ([]byte, error) {
return gxml.Encode(j.ToMap(), rootTag...)
return gxml.Encode(j.Map(), rootTag...)
}
func (j *Json) ToXmlString(rootTag ...string) (string, error) {
@ -79,7 +79,7 @@ func (j *Json) ToXmlString(rootTag ...string) (string, error) {
}
func (j *Json) ToXmlIndent(rootTag ...string) ([]byte, error) {
return gxml.EncodeWithIndent(j.ToMap(), rootTag...)
return gxml.EncodeWithIndent(j.Map(), rootTag...)
}
func (j *Json) ToXmlIndentString(rootTag ...string) (string, error) {

View File

@ -1,104 +0,0 @@
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gjson
import "github.com/gogf/gf/util/gconv"
// ToMap converts current Json object to map[string]interface{}.
// It returns nil if fails.
// Deprecated, use Map instead.
func (j *Json) ToMap() map[string]interface{} {
j.mu.RLock()
defer j.mu.RUnlock()
return gconv.Map(*(j.p))
}
// ToArray converts current Json object to []interface{}.
// It returns nil if fails.
// Deprecated, use Array instead.
func (j *Json) ToArray() []interface{} {
j.mu.RLock()
defer j.mu.RUnlock()
return gconv.Interfaces(*(j.p))
}
// ToStruct converts current Json object to specified object.
// The <pointer> should be a pointer type of *struct.
// Deprecated, use Struct instead.
func (j *Json) ToStruct(pointer interface{}, mapping ...map[string]string) error {
j.mu.RLock()
defer j.mu.RUnlock()
return gconv.Struct(*(j.p), pointer, mapping...)
}
// ToStructDeep converts current Json object to specified object recursively.
// The <pointer> should be a pointer type of *struct.
// Deprecated, use Struct instead.
func (j *Json) ToStructDeep(pointer interface{}, mapping ...map[string]string) error {
j.mu.RLock()
defer j.mu.RUnlock()
return gconv.StructDeep(*(j.p), pointer, mapping...)
}
// ToStructs converts current Json object to specified object slice.
// The <pointer> should be a pointer type of []struct/*struct.
// Deprecated, use Structs instead.
func (j *Json) ToStructs(pointer interface{}, mapping ...map[string]string) error {
j.mu.RLock()
defer j.mu.RUnlock()
return gconv.Structs(*(j.p), pointer, mapping...)
}
// ToStructsDeep converts current Json object to specified object slice recursively.
// The <pointer> should be a pointer type of []struct/*struct.
// Deprecated, use Structs instead.
func (j *Json) ToStructsDeep(pointer interface{}, mapping ...map[string]string) error {
j.mu.RLock()
defer j.mu.RUnlock()
return gconv.StructsDeep(*(j.p), pointer, mapping...)
}
// ToScan automatically calls Struct or Structs function according to the type of parameter
// <pointer> to implement the converting..
// Deprecated, use Scan instead.
func (j *Json) ToScan(pointer interface{}, mapping ...map[string]string) error {
return gconv.Scan(*(j.p), pointer, mapping...)
}
// ToScanDeep automatically calls StructDeep or StructsDeep function according to the type of
// parameter <pointer> to implement the converting..
// Deprecated, use Scan instead.
func (j *Json) ToScanDeep(pointer interface{}, mapping ...map[string]string) error {
return gconv.ScanDeep(*(j.p), pointer, mapping...)
}
// ToMapToMap converts current Json object to specified map variable.
// The parameter of <pointer> should be type of *map.
// Deprecated, use MapToMap instead.
func (j *Json) ToMapToMap(pointer interface{}, mapping ...map[string]string) error {
j.mu.RLock()
defer j.mu.RUnlock()
return gconv.MapToMap(*(j.p), pointer, mapping...)
}
// ToMapToMaps converts current Json object to specified map variable slice.
// The parameter of <pointer> should be type of []map/*map.
// Deprecated, use MapToMaps instead.
func (j *Json) ToMapToMaps(pointer interface{}, mapping ...map[string]string) error {
j.mu.RLock()
defer j.mu.RUnlock()
return gconv.MapToMaps(*(j.p), pointer, mapping...)
}
// ToMapToMapsDeep converts current Json object to specified map variable slice recursively.
// The parameter of <pointer> should be type of []map/*map.
// Deprecated, use MapToMaps instead.
func (j *Json) ToMapToMapsDeep(pointer interface{}, mapping ...map[string]string) error {
j.mu.RLock()
defer j.mu.RUnlock()
return gconv.MapToMapsDeep(*(j.p), pointer, mapping...)
}

View File

@ -100,7 +100,7 @@ func Example_conversionToStruct() {
Array []string
}
users := new(Users)
if err := j.ToStruct(users); err != nil {
if err := j.Struct(users); err != nil {
panic(err)
}
fmt.Printf(`%+v`, users)

View File

@ -353,7 +353,7 @@ func Test_Convert2(t *testing.T) {
t.Assert(j.GetGTime("time").Format("Y-m-d"), "2019-06-12")
t.Assert(j.GetDuration("time").String(), "0s")
err := j.ToStruct(&name)
err := j.Struct(&name)
t.Assert(err, nil)
t.Assert(name.Name, "gf")
//j.Dump()
@ -369,7 +369,7 @@ func Test_Convert2(t *testing.T) {
t.Assert(err, nil)
j = gjson.New(`[1,2,3]`)
t.Assert(len(j.ToArray()), 3)
t.Assert(len(j.Array()), 3)
})
}
@ -400,7 +400,7 @@ func Test_Basic(t *testing.T) {
err = j.Remove("1")
t.Assert(err, nil)
t.Assert(j.Get("0"), 1)
t.Assert(len(j.ToArray()), 2)
t.Assert(len(j.Array()), 2)
j = gjson.New(`[1,2,3]`)
// If index 0 is delete, its next item will be at index 0.
@ -408,13 +408,13 @@ func Test_Basic(t *testing.T) {
t.Assert(j.Remove("0"), nil)
t.Assert(j.Remove("0"), nil)
t.Assert(j.Get("0"), nil)
t.Assert(len(j.ToArray()), 0)
t.Assert(len(j.Array()), 0)
j = gjson.New(`[1,2,3]`)
err = j.Remove("3")
t.Assert(err, nil)
t.Assert(j.Get("0"), 1)
t.Assert(len(j.ToArray()), 3)
t.Assert(len(j.Array()), 3)
j = gjson.New(`[1,2,3]`)
err = j.Remove("0.3")

View File

@ -61,7 +61,7 @@ func Test_MapAttributeConvert(t *testing.T) {
Title map[string]interface{}
}{}
err = j.ToStruct(&tx)
err = j.Struct(&tx)
gtest.Assert(err, nil)
t.Assert(tx.Title, g.Map{
"l1": "标签1", "l2": "标签2",
@ -76,7 +76,7 @@ func Test_MapAttributeConvert(t *testing.T) {
Title map[string]string
}{}
err = j.ToStruct(&tx)
err = j.Struct(&tx)
gtest.Assert(err, nil)
t.Assert(tx.Title, g.Map{
"l1": "标签1", "l2": "标签2",

View File

@ -230,14 +230,14 @@ func Test_Convert(t *testing.T) {
err := p.GetStruct("person", &name)
t.Assert(err, nil)
t.Assert(name.Name, "gf")
t.Assert(p.ToMap()["name"], "gf")
err = p.ToStruct(&name)
t.Assert(p.Map()["name"], "gf")
err = p.Struct(&name)
t.Assert(err, nil)
t.Assert(name.Name, "gf")
//p.Dump()
p = gparser.New(`[0,1,2]`)
t.Assert(p.ToArray()[0], 0)
t.Assert(p.Array()[0], 0)
})
}