【Go学习】macOS+IDEA运行golang项目,报command-line-arguments,undefined

写在前面的话:idea如何配置golang,自行百度

问题1:通过idea的terminal执行go test报错

bash 复制代码
✘ xxxxx@macdeMacBook-Pro-3  /Volumes/mac/.../LearnGoWithTests/hello  go test
go: go.mod file not found in current directory or any parent directory; see 'go help modules'

这个问题就是当前目录没有go.mod文件,直接用go命令生成一个即可(example.com/m 可以随便自定义,比如:helloWorld)

bash 复制代码
✘ xxxxx@macdeMacBook-Pro-3  /Volumes/mac/.../LearnGoWithTests/hello  go mod init example.com/m      
go: creating new go.mod: module example.com/m
go: to add module requirements and sums:
        go mod tidy

再次执行go test就没问题了(下面的虽然case FAIL了,但是执行是没问题的)

bash 复制代码
✘ xxxxx@macdeMacBook-Pro-3  /Volumes/mac/.../LearnGoWithTests/hello  go test
PASS
ok      example.com/m   0.470s
问题2:通过idea的Run或Debug执行,就会报command-line-arguments,undefined

【解决方法】打开preferences,如下图设置一下即可

然后再用Run或Debug执行就可以了,如下图

相关推荐
通信仿真实验室26 分钟前
(10)MATLAB莱斯(Rician)衰落信道仿真1
开发语言·matlab
勿语&29 分钟前
Element-UI Plus 暗黑主题切换及自定义主题色
开发语言·javascript·ui
吾爱星辰4 小时前
Kotlin 处理字符串和正则表达式(二十一)
java·开发语言·jvm·正则表达式·kotlin
ChinaDragonDreamer4 小时前
Kotlin:2.0.20 的新特性
android·开发语言·kotlin
IT良4 小时前
c#增删改查 (数据操作的基础)
开发语言·c#
Kalika0-05 小时前
猴子吃桃-C语言
c语言·开发语言·数据结构·算法
_.Switch5 小时前
Python Web 应用中的 API 网关集成与优化
开发语言·前端·后端·python·架构·log4j
代码雕刻家5 小时前
课设实验-数据结构-单链表-文教文化用品品牌
c语言·开发语言·数据结构
一个闪现必杀技5 小时前
Python入门--函数
开发语言·python·青少年编程·pycharm
Fan_web5 小时前
jQuery——事件委托
开发语言·前端·javascript·css·jquery