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

相关推荐
在放️42 分钟前
Python 爬虫 · 第三方代理接入与合规使用
开发语言·爬虫·python
KANGBboy1 小时前
java知识五(继承)
java·开发语言
c++之路1 小时前
Bazel C++ 构建系列文档(三):构建第一个 C++ 项目
开发语言·c++
AI人工智能+电脑小能手1 小时前
【大白话说Java面试题 第117题】【并发篇】第17题:线程有几种状态,之间如何转换?
java·开发语言·面试
聚名网2 小时前
域名net,com,cn有区别吗?有哪些不同呢?
服务器·开发语言·php
牛油果子哥q2 小时前
STL set与map底层精讲,红黑树适配原理、有序去重特性、迭代器遍历、API实战与面试核心考点全解
开发语言·数据结构·c++·面试
foundbug9992 小时前
直流电机 PID 速度控制 MATLAB 仿真程序
开发语言·matlab
Tian_Hang3 小时前
C++原型模式(Protype)
开发语言·c++·算法
天天讯通3 小时前
OKCC 呼叫中心安全性能全解析:技术防护与管理措施指南
大数据·开发语言·网络·人工智能·安全·语音识别
xufengzhu4 小时前
第三方 Python 库 redis-py + hiredis 的使用
开发语言·redis·python