因为直接上手项目,并没有系统去学习go语言,其实这个问题只是golang的一个语言特性。

golang cannot refer to unexported name 解决方案

因为项目框架别人搭建的,我直接导入进来发现一大堆报错。

golang cannot refer to unexported name 解决方案

其实是在搭建的过程中所有的方法都调用错了

模块中的方法要给其他模块调用,方法名首字母必须大写,例如:

golang cannot refer to unexported name 解决方案

golang cannot refer to unexported name 解决方案

这样引用就会报错:

golang cannot refer to unexported name 解决方案

解决方案就是给方法名大写,没错,就这么简单,但是我不知道之前搭建框架的人代码是怎么撸出来的。。。

golang cannot refer to unexported name 解决方案

这样就可以成功调用啦!

相关文章: