jjzjj

unexported

全部标签

pointers - 调用结构函数给出 "cannot refer to unexported field or method"

我有这样的结构:typeMyStructstruct{Idstring}和函数:func(m*MyStruct)id(){//doingsomethingwithidhere}我还有一个这样的结构:typeMyStruct2struct{m*MyStruct}现在我有一个函数:funcfoo(str*MyStruct2){str.m.id()}但是我在编译时遇到错误:str.m.idundefined(cannotrefertounexportedfieldormethodmypackage.(*MyStruct)."".id如何正确调用这个函数? 最佳答案

pointers - 调用结构函数给出 "cannot refer to unexported field or method"

我有这样的结构:typeMyStructstruct{Idstring}和函数:func(m*MyStruct)id(){//doingsomethingwithidhere}我还有一个这样的结构:typeMyStruct2struct{m*MyStruct}现在我有一个函数:funcfoo(str*MyStruct2){str.m.id()}但是我在编译时遇到错误:str.m.idundefined(cannotrefertounexportedfieldormethodmypackage.(*MyStruct)."".id如何正确调用这个函数? 最佳答案

go - 为什么反射要与 UNEXPORTED Struct 和 Unexported Fields 一起使用?

我希望在代码中使用结构Dish导出为Dish。当未导出结构dish并且看不到其中未导出的字段时,我预计程序会失败。(好的,我可以看到未导出的字段出现在导出的结构中,但即使这样似乎也是错误的)。但是程序仍然可以正常工作??没有导出的反射包怎么能看到'dish'?------------程序如下--------//修改示例来自博客:http://merbist.com/2011/06/27/golang-reflection-exampl/packagemainimport("fmt""reflect")funcmain(){//iteratethroughtheattributesofa

go - 为什么反射要与 UNEXPORTED Struct 和 Unexported Fields 一起使用?

我希望在代码中使用结构Dish导出为Dish。当未导出结构dish并且看不到其中未导出的字段时,我预计程序会失败。(好的,我可以看到未导出的字段出现在导出的结构中,但即使这样似乎也是错误的)。但是程序仍然可以正常工作??没有导出的反射包怎么能看到'dish'?------------程序如下--------//修改示例来自博客:http://merbist.com/2011/06/27/golang-reflection-exampl/packagemainimport("fmt""reflect")funcmain(){//iteratethroughtheattributesofa

go - 马提尼绑定(bind) "cannot return value obtained from unexported field or method"

我有以下路线:m.Post("/users",binding.Bind(models.User{}),func(usermodels.User,rrender.Render)当我尝试执行Post请求时收到以下错误消息:"PANIC:reflect.Value.Interface:cannotreturnvalueobtainedfromunexportedfieldormethod"typeUserstruct{idintUUIDstring`json:"uuid"`Usernamestring`json:"userName"form:"userName"binding:"requir

go - "Exported type should have comment or be unexported"golang VS 代码

我在Go中尝试了这段代码:typeAgentstruct{namestring//NotexportedcategoryIdint//Notexported}VSCode报告了以下问题:exportedtypeAgentshouldhavecommentorbeunexported警告有点烦人。所以我有以下问题:如何摆脱它?我应该发表什么评论?是否有任何默认评论模板?它要求我发表评论,但默认情况下不让我添加评论。 最佳答案 只需在其上方添加注释,以您的类型(或函数、方法等)的名称开头,如下所示://Agentis...typeAge

pointers - 调用 struct 函数给出 "cannot refer to unexported field or method"

我有一个类似这样的结构:typeMyStructstruct{Idstring}和功能:func(m*MyStruct)id(){//doingsomethingwithidhere}我还有另一个这样的结构:typeMyStruct2struct{m*MyStruct}现在我有一个函数:funcfoo(str*MyStruct2){str.m.id()}但我在编译时遇到错误:str.m.idundefined(cannotrefertounexportedfieldormethodmypackage.(*MyStruct)."".id如何正确调用这个函数?