运行程序时报go: cannot find main module, but found .git/config in
编写单元测试,运行时报下面的错误
haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/haimait/learn/base/cheshi01$ go test
go: cannot find main module, but found .git/config in /media/haima/34E401CC64DD0E28/site/go/src/haimait/learn
to create a module there, run:
cd ../.. && go mod init
出错原因是开启了go mod,但是没有初使化生成go.mod文件
解决方法一:
关闭gomod
haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/haimait/learn/base/cheshi01$ export GO111MODULE=off
haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/haimait/learn/base/cheshi01$ go env
GO111MODULE="off"
…… #省略
haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/haimait/learn/base/cheshi01$ go test
--- FAIL: TestAdd2 (0.00s)
cheshi01_test.go:16: result is wrong!
FAIL
exit status 1
FAIL haimait/learn/base/cheshi01 0.002s
解决方法二
haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/haimait/learn/base/cheshi01$ go mod init
go: creating new go.mod: module haimait/learn/base/cheshi01
haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/haimait/learn/base/cheshi01$ go mod tidy
haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/haimait/learn/base/cheshi01$ go test
--- FAIL: TestAdd2 (0.00s)
cheshi01_test.go:16: result is wrong!
FAIL
exit status 1
FAIL haimait/learn/base/cheshi01 0.002s
haima@haima-PC:/media/haima/34E401CC64DD0E28/site/go/src/haimait/learn/base/cheshi01$ go test -v
=== RUN TestAdd1
TestAdd1: cheshi01_test.go:11: result is right!
--- PASS: TestAdd1 (0.00s)
=== RUN TestAdd2
TestAdd2: cheshi01_test.go:16: result is wrong!
--- FAIL: TestAdd2 (0.00s)
FAIL
exit status 1
FAIL haimait/learn/base/cheshi01 0.002s
运行程序时报go: cannot find main module, but found .git/config in的更多相关文章
- visual studio code运行时报错,无法将“cnpm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称,Cannot find module 'webpack'
前言 因公司技术需求,这段时间成功进入了Vue 2.0 的坑,刚用起Visual Studio Code,却发现问题很多,发现一个错误:cnpm : 无法将“cnpm”项识别为 cmdlet.函数.脚 ...
- eclipse运行程序时报java.lang.OutOfMemoryError: Java heap space内存不足问题
System.setProperty("webdriver.firefox.bin", "D:\\Mozilla Firefox\\firefox.exe"); ...
- Android开发eclipse运行程序时报timeout的解决方法
eclipse开发Android程序时,忽然莫名其妙报这个错,之前还好好的.忽然就不行了. Failed to install xxx.apk on device~~~: timeout 尝试过手机里 ...
- 在运行程序时报错:"如果在 Code First 模式下使用,则使用 T4 模板为 Database First 和 Model First 开发生成的代码可能无法 正常运行。若要继续使用 Database First 或 Model First,请确保在执行应用程序的 config 文件中指 定 Entity Framework 连接字符串。若要将这些从 Database First 或 Mod
解决方案: 将context类下的方法“OnModelCreating”修改为: protected override void OnModelCreating(DbModelBuilder mode ...
- 运行项目npm run dev时报错: ~Error: Cannot find module 'webpack-cli/bin/config-yargs', 原因是
webpack@3.X运行项目npm run dev时报错: ~Error: Cannot find module 'webpack-cli/bin/config-yargs' 我的原因是: web ...
- intellij idea运行Android程序时报错;Unable to locate adb within SDK
环境:intellij idea15 问题:运行Android时报错Throwable:Unable to locate adb within SDK 解决方法:在SDK安装目录的\platfor ...
- idea运行Tomcat的servlet程序时报500错误解决方法
今天在测试使用Tomcat运行servlet小程序时,在传递参数时,出现了如上错误. 开始我以为是配置出了问题,就把项目删除了又建立了一遍,结果亦然. 经过仔细排查,发现问题,先说明问题原因:idea ...
- ddt运行测试方法时报错AttributeError: type object 'TestHttpRq' has no attribute 'test_http_rq_login'
import unittest import ddt #装饰器 from ddt import ddt,data,unpack #导入ddt中的各个模块 from homework.unittest_ ...
- C#程序集系列01,用记事本编写C#,IL代码,用DOS命令编译程序集,运行程序
本篇主要体验:编写C#,IL代码,用"VS2012开发人员命令提示"编译成程序集,并运行程序. □ C#文件编译为程序集 →在F盘创建as文件夹→在as文件夹下创建MyClass. ...
- 《Erlang程序设计》学习笔记-第1章 编译并运行程序
http://blog.csdn.net/karl_max/article/details/3976372 1. erlang:halt()可以即刻停止系统运行. 2. q()命令可以完成文件和数据库 ...
随机推荐
- Modbus报文详解
Modbus是一种串行通信协议,最初由Modicon公司(现为施耐德电气的一部分)在1979年为使用其PLC(可编程逻辑控制器)而开发.Modbus已成为工业领域内广泛使用的一种通信协议,特别是对于监 ...
- GPTCache使用
1.概述 传统应用开发中,为了提升系统的查询性能,往往会在系统架构设计中加入缓存机制.在AI大模型领域,虽然功能非常强大,但是使用成本也是非常昂贵的,比如OpenAI的GPT-4按照token的个数来 ...
- 【Java面试题】Spring
八.Spring 57)什么是 Spring 的依赖注入 IOC( Inversion of Control )的⼀个重点是在系统运行中,动态的向某个对象提供它所需要的其他对象. 其中依赖注入(DI ...
- #线段树,排列组合#洛谷 6108 [Ynoi2009] rprsvq
题目链接 分析 维护区间和以及区间平方和都比较简单,考虑答案是什么,根据方差公式的变形. \[ans=\frac{\sum_{j=1}^na_j^2}{n}-\frac{(\sum_{j=1}^na_ ...
- #扩展欧拉定理#CF906D Power Tower
题目 给定一个数列,有\(m\)组询问 定义 \[\large f(x-1)={a_x}^{f(x)} \] 若 \(f(r)=a_r\) 求 \(f(l)\) 对固定的 \(mod\) 取模 分析 ...
- #模拟#洛谷 2327 [SCOI2005]扫雷
题目 分析 考虑最多只有两种情况,因为确定一个位置其它位置随即也能确定, 那么指定第一个位置有没有雷然后判断一下后面推出的雷数是否为0或1,不是显然不行 代码 #include <cstdio& ...
- JDK9的新特性:JVM的xlog
目录 简介 xlog的使用 selections output decorators 总结 简介 在java程序中,我们通过日志来定位和发现项目中可能出现的问题.在现代java项目中,我们使用log4 ...
- 并发编程面试必备之ConcurrentHashMap源码解析
ConcurrentHashMap在我的面试生涯中,10次有8次是会被问到的,记得刚毕业那会,被问到ConcurrentHashMap源码的无助与苦涩,无奈只能网上找了一些教程,背一背,才算是蒙混过关 ...
- MogDB 使用向量化执行引擎进行调优
MogDB 使用向量化执行引擎进行调优 本文出处:https://www.modb.pro/db/430318 MogDB 数据库支持行执行引擎和向量化执行引擎,分别对应行存表和列存表. 一次一个 b ...
- 记一次 Go 调用系统命令出现的问题分析
首先在程序中封装了下面一个函数用来执行系统命令: // 执行系统命令 func executeCommand(command string, output, outerr io.Writer) err ...