treewide: make explicit calls to JSONDict.Remove() and JSONDict.RemoveIgnoreCase

This commit is contained in:
Yousong Zhou
2018-08-09 04:30:56 +00:00
parent fd352dbdbb
commit 1bf9036c83
9 changed files with 52 additions and 13 deletions
Generated
+3 -2
View File
@@ -567,9 +567,10 @@
revision = "bbd99532a768d2fe369079ceda730e30726ae1a6"
[[projects]]
branch = "release/2.0.0"
name = "github.com/yunionio/jsonutils"
packages = ["."]
revision = "6dd39f8579af6c6b61b971eb3a1ccf55e724b0ca"
revision = "0f3f30adfdac3dec6ffbbfb72116f6f908134f63"
[[projects]]
branch = "master"
@@ -904,6 +905,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "1fdd79d4d8791f7e87a3740b3807ea84f6306ecac3095d32a1ccf39b48be1f18"
inputs-digest = "aa5af605c21bc592cbc237ad3539bc2cd9bbe5b8495c6c2d22e4a3bd8b148633"
solver-name = "gps-cdcl"
solver-version = 1
+1 -1
View File
@@ -30,7 +30,7 @@
version = "0.2.2"
[[constraint]]
revision = "6dd39f8579af6c6b61b971eb3a1ccf55e724b0ca"
branch = "release/2.0.0"
name = "github.com/yunionio/jsonutils"
[[constraint]]
+2 -2
View File
@@ -665,7 +665,7 @@ func doCreateItem(manager IModelManager, ctx context.Context, userCred mcclient.
generateName, _ := dataDict.GetString("generate_name")
if len(generateName) > 0 {
dataDict.Remove("generate_name", true)
dataDict.Remove("generate_name")
dataDict.Add(jsonutils.NewString(GenerateName(manager, ownerProjId, generateName)), "name")
} else {
name, _ := data.GetString("name")
@@ -756,7 +756,7 @@ func expandMultiCreateParams(data jsonutils.JSONObject, count int) ([]jsonutils.
return nil, httperrors.NewInputParameterError("Missing name or generate_name")
}
jsonDict.Add(jsonutils.NewString(name), "generate_name")
jsonDict.Remove("name", false)
jsonDict.RemoveIgnoreCase("name")
}
ret := make([]jsonutils.JSONObject, count)
for i := 0; i < count; i += 1 {
+3 -3
View File
@@ -270,17 +270,17 @@ func (manager *SOpsLogManager) ListItemFilter(ctx context.Context, q *sqlchemy.S
}
objTypes := jsonutils.GetQueryStringArray(queryDict, "obj_type")
if objTypes != nil && len(objTypes) > 0 {
queryDict.Remove("obj_type", false)
queryDict.RemoveIgnoreCase("obj_type")
q = q.Filter(sqlchemy.In(q.Field("obj_type"), objTypes))
}
objIds := jsonutils.GetQueryStringArray(queryDict, "obj_id")
if objIds != nil && len(objIds) > 0 {
queryDict.Remove("obj_id", false)
queryDict.RemoveIgnoreCase("obj_id")
q = q.Filter(sqlchemy.OR(sqlchemy.In(q.Field("obj_id"), objIds), sqlchemy.In(q.Field("obj_name"), objIds)))
}
action := jsonutils.GetQueryStringArray(queryDict, "action")
if action != nil && len(action) > 0 {
queryDict.Remove("action", false)
queryDict.RemoveIgnoreCase("action")
q = q.Filter(sqlchemy.In(q.Field("action"), action))
}
if !userCred.IsSystemAdmin() {
+1 -1
View File
@@ -196,7 +196,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
isBMstr, _ := queryDict.GetString("baremetal")
if len(isBMstr) > 0 && utils.ToBool(isBMstr) {
queryDict.Add(jsonutils.NewString(HYPERVISOR_BAREMETAL), "hypervisor")
queryDict.Remove("baremetal", true)
queryDict.Remove("baremetal")
}
hypervisor, _ := queryDict.GetString("hypervisor")
if len(hypervisor) > 0 {
+1 -1
View File
@@ -119,7 +119,7 @@ func (this *ImageManager) List(session *mcclient.ClientSession, params jsonutils
path = fmt.Sprintf("%s/detail", path)
}
dictparams, _ := params.(*jsonutils.JSONDict)
dictparams.Remove("details", false)
dictparams.RemoveIgnoreCase("details")
qs := params.QueryString()
if len(qs) > 0 {
path = fmt.Sprintf("%s?%s", path, qs)
+2 -2
View File
@@ -20,8 +20,8 @@ func (this *UsageManager) GetGeneralUsage(session *mcclient.ClientSession, param
url = fmt.Sprintf("%s/%s/%s", url, range_type, range_id)
}
dict := params.(*jsonutils.JSONDict)
dict.Remove("range_type", true)
dict.Remove("range_id", true)
dict.Remove("range_type")
dict.Remove("range_id")
qs := dict.QueryString()
if len(qs) > 0 {
url = fmt.Sprintf("%s?%s", url, qs)
+26 -1
View File
@@ -42,11 +42,36 @@ func NewFloat(val float64) *JSONFloat {
return &JSONFloat{data: val}
}
func NewBool(val bool) *JSONBool {
if val {
return JSONTrue
}
return JSONFalse
}
func (this *JSONDict) Set(key string, value JSONObject) {
this.data[key] = value
}
func (this *JSONDict) Remove(key string, caseSensitive bool) bool {
func (this *JSONDict) Remove(key string) bool {
return this.remove(key, true)
}
func (this *JSONDict) RemoveIgnoreCase(key string) bool {
someRemoved := false
for {
removed := this.remove(key, false)
if !removed {
break
}
if !someRemoved {
someRemoved = true
}
}
return someRemoved
}
func (this *JSONDict) remove(key string, caseSensitive bool) bool {
_, rk, ok := dictGet(this.data, key, caseSensitive)
if ok {
delete(this.data, rk)
+13
View File
@@ -0,0 +1,13 @@
package jsonutils
func (this *JSONString) Length() int {
return len(this.data)
}
func (this *JSONDict) Length() int {
return len(this.data)
}
func (this *JSONArray) Length() int {
return len(this.data)
}