码迷,mamicode.com
首页 > 其他好文 > 详细

运行程序时报go: cannot find main module, but found .git/config in

时间:2020-11-26 14:24:36      阅读:5      评论:0      收藏:0      [点我收藏+]

标签:ati   off   没有   ase   wrong   pre   creating   find   config   

编写单元测试,运行时报下面的错误

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

标签:ati   off   没有   ase   wrong   pre   creating   find   config   

原文地址:https://www.cnblogs.com/haima/p/14020284.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!