mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-20 00:50:06 +08:00
fix: structure ignore tag not working in nest struct
This commit is contained in:
parent
90470ac304
commit
91f5593f4e
@ -517,6 +517,10 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e
|
||||
fieldName = tagValue
|
||||
}
|
||||
|
||||
if tagValue == "-" {
|
||||
continue
|
||||
}
|
||||
|
||||
rawMapKey := reflect.ValueOf(fieldName)
|
||||
rawMapVal := dataVal.MapIndex(rawMapKey)
|
||||
if !rawMapVal.IsValid() {
|
||||
|
||||
@ -308,3 +308,27 @@ func TestStructure_Ignore(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, s.MustIgnore, "oldData")
|
||||
}
|
||||
|
||||
func TestStructure_IgnoreInNest(t *testing.T) {
|
||||
rawMap := map[string]any{
|
||||
"-": "newData",
|
||||
}
|
||||
|
||||
type TP struct {
|
||||
MustIgnore string `test:"-"`
|
||||
}
|
||||
|
||||
s := struct {
|
||||
TP
|
||||
}{TP{MustIgnore: "oldData"}}
|
||||
|
||||
err := decoder.Decode(rawMap, &s)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, s.MustIgnore, "oldData")
|
||||
|
||||
// test omitempty
|
||||
delete(rawMap, "-")
|
||||
err = decoder.Decode(rawMap, &s)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, s.MustIgnore, "oldData")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user