x
This commit is contained in:
@@ -32,7 +32,8 @@ type fieldInfo struct {
|
||||
mapField *fieldInfo
|
||||
}
|
||||
|
||||
// FillDefault fills the default values for the given v.
|
||||
// FillDefault fills the default values for the given v,
|
||||
// and the premise is that the value of v must be guaranteed to be empty
|
||||
func FillDefault(v any) error {
|
||||
return fillDefaultUnmarshaler.Unmarshal(map[string]any{}, v)
|
||||
}
|
||||
|
||||
@@ -1078,4 +1078,16 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
||||
assert.Equal(t, st.A, "a")
|
||||
assert.Equal(t, st.C, "c")
|
||||
})
|
||||
|
||||
t.Run("has vaue", func(t *testing.T) {
|
||||
type St struct {
|
||||
A string `json:",default=a"`
|
||||
B string
|
||||
}
|
||||
var st = St{
|
||||
A: "b",
|
||||
}
|
||||
err := FillDefault(&st)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user