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

相关推荐
点云SLAM9 小时前
C++依赖注入(Dependency Injection DI)vs单例设计模式(Singleton)
开发语言·c++·单例模式·设计模式·日志配置·依赖注入di·大项目系统
Hello.Reader9 小时前
连接四元组它为什么重要,以及它和端口复用(SO_REUSEPORT)的关系(Go 实战)
开发语言·后端·golang
静待_花开10 小时前
java日期格式化
java·开发语言
我是一只小青蛙88810 小时前
二分查找巧解数组范围问题
java·开发语言·算法
Jayden_Ruan10 小时前
C++水仙花数
开发语言·c++·算法
lsx20240610 小时前
SQL UNIQUE约束详解
开发语言
一只爱做笔记的码农10 小时前
【C#】如何把资源打包成zip压缩包,内嵌进程序中,然后程序可以直接用代码进行访问,无需解压
开发语言·c#
Renhao-Wan10 小时前
数据结构在Java后端开发与架构设计中的实战应用
java·开发语言·数据结构
LawrenceLan10 小时前
16.Flutter 零基础入门(十六):Widget 基础概念与第一个 Flutter 页面
开发语言·前端·flutter·dart
sheji341610 小时前
【开题答辩全过程】以 基于Java的智慧党建管理系统的设计与实现为例,包含答辩的问题和答案
java·开发语言