func TestCase(t *testing.T) {
type DstStruct struct {
state string
Id int32
State string
}
type MockState string
type SrcStruct struct {
Id int32
State MockState
}
src := &SrcStruct{
Id: 1,
State: "test_str",
}
dst := DstStruct{}
_ = copier.CopyWithOption(&dst, src, copier.Option{
Converters: []copier.TypeConverter{
{
SrcType: "",
DstType: MockState(""),
Fn: func(src interface{}) (interface{}, error) {
s, _ := src.(string)
return MockState(s), nil
},
},
},
})
if dst.Id != 1 {
t.Errorf("dst.id expect is 1, but it is '%v'", dst.Id)
}
if dst.State != "test_str" {
t.Errorf("dst.State expect is 'test_str', but it is '%v'", dst.State)
}
}
I believe it's a case-sensitive issue. Removing DstStruct.state should resolve it, but since that is a private field, it should not be causing the problem.
I discovered that this is not a bug issue. I found the optional CaseSensitive and opened it. This problem will be fixed.
https://go.dev/play/p/JZLLT4TG1Ho
Reproducible Example
reproduce
Description
I believe it's a case-sensitive issue. Removing DstStruct.state should resolve it, but since that is a private field, it should not be causing the problem.