【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执行就可以了,如下图

相关推荐
WJ.Polar10 小时前
Java封装、继承、多态
java·开发语言
king135987455010 小时前
LFM2.5-24B-A2B Mac 本地部署:内存估算、GGUF/MLX 与 Python 预检脚本
人工智能·macos
96245610 小时前
Go EVM 链上数据平台实践:从 RPC Demo 到可演进架构
rpc·架构·golang
摇滚侠10 小时前
Java 中如何表示负数,有符号和无符号的区别,补码的计算规则,char byte short int long 的范围
java·开发语言
weixin_3077791310 小时前
C++代码实现MATLAB中的fitrtree函数功能
开发语言·c++·算法·matlab
骑着蜗牛撵大象32710 小时前
链路层不只是 MAC:以太网帧、ARP 与 802.1Q VLAN 的逐跳拆解
计算机网络·macos·ar·vlan·mac地址·链路层
爱读书的小胖11 小时前
Codewars:Rot13(C)解题分析
c语言·开发语言
鸽鸽程序猿11 小时前
【项目】【在线判题系统】b端题目增删改
开发语言·python
Lhappy嘻嘻11 小时前
读懂 JVM:内存模型、类加载机制、分代回收
java·开发语言·jvm
weixin_3077791312 小时前
C++代码实现MATLAB中的spectralcluster函数功能
开发语言·c++·算法·matlab