Skip to content

Commit

Permalink
fix(hashmap): switch to StructToHashMapWithXML
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed May 28, 2022
1 parent 42d4e6b commit 5012e96
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions object/hashMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func MergeHashMap(toMap *HashMap, subMaps ...*HashMap) *HashMap {
for _, subMap := range subMaps {
if subMap != nil {
// 迭代每个HashMap
for k, v := range (*subMap) {
for k, v := range *subMap {
toV := (*toMap)[k]

// if the key is not exist in toMap
Expand All @@ -41,7 +41,6 @@ func MergeHashMap(toMap *HashMap, subMaps ...*HashMap) *HashMap {
return toMap
}


// ------------------------------- Replace --------------------------------------------
func ReplaceHashMapRecursive(toMap *HashMap, subMaps ...*HashMap) *HashMap {
if toMap == nil {
Expand Down Expand Up @@ -77,7 +76,7 @@ func HashMapToStringMap(obj *HashMap) (newMap *StringMap, err error) {

}

func StructToHashMapWithTag(obj interface{}, tag string) (newMap *HashMap, err error) {
func StructToHashMapWithXML(obj interface{}) (newMap *HashMap, err error) {

newMap = &HashMap{}

Expand All @@ -90,10 +89,8 @@ func StructToHashMapWithTag(obj interface{}, tag string) (newMap *HashMap, err e
for i := 0; i < e.NumField(); i++ {
field := e.Field(i).Interface()

key := e.Type().Field(i).Name
if tag != "" {
key = e.Type().Field(i).Tag.Get(tag)
}
key := e.Type().Field(i).Tag.Get("xml")

(*newMap)[key] = field

}
Expand Down

0 comments on commit 5012e96

Please sign in to comment.