相关疑难解决方法(0)

cmp.Equal 给出紧急消息“无法处理 .. 处的未导出字段”

我有一个自定义结构,其中有一个未导出的字段。我希望能够将值与此结构的类型进行比较,但我收到如下恐慌消息:

panic: cannot handle unexported field at ...
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
Run Code Online (Sandbox Code Playgroud)

示例代码:

panic: cannot handle unexported field at ...
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
Run Code Online (Sandbox Code Playgroud)

如何修复此错误并比较变量?

comparison struct go go-cmp

5
推荐指数
1
解决办法
4008
查看次数

标签 统计

comparison ×1

go ×1

go-cmp ×1

struct ×1