I’m learning from a Go project using Windows (https://geektutu.com/post/geeorm-day1.html), and I’ve encountered an issue with package management and module imports that I can’t seem to resolve. I’m trying to import a local package and a third-party package, but Go is unable to locate either of them.
I am a beginner of Go and the tutorial reminds me:
Go sqlite3 relies on gcc, and if this code runs on Windows, Mingw or other toolkits containing gcc compilers need to be installed.
However, both g++ --version
and gcc --version
can work out in my project terminal, and mingw64/bin
has already be put to PATH
.
Error Messages:
- For my local package
geeorm
:
7days-golanggee-ormday1-database-sqlcmd_testmain.go:5:2: package geeorm is not in std (C:Program FilesGosrcgeeorm)
- For the third-party package
github.com/mattn/go-sqlite3
:
7days-golanggee-ormday1-database-sqlcmd_testmain.go:6:2: no required module provides package github.com/mattn/go-sqlite3: go.mod file not found in current directory or any parent directory; see 'go help modules'
This may make more sense than the previous one because in my go.mod
the line require github.com/mattn/go-sqlite3 v2.0.3+incompatible
is still underlined.
File structure:
V:codego7days-golanggee-ormday1-database-sql
|_ cmd_test
|_ main.go
|_ go.mod (after running go mod init gee-orm)
go.mod
looks like
module geeorm
go 1.13
require github.com/mattn/go-sqlite3 v2.0.3+incompatible
main.go
looks like
package main
import (
"fmt"
"geeorm"
_ "github.com/mattn/go-sqlite3"
)
func main() {
engine, _ := geeorm.NewEngine("sqlite3", "gee.db")
defer engine.Close()
s := engine.NewSession()
_, _ = s.Raw("DROP TABLE IF EXISTS User;").Exec()
_, _ = s.Raw("CREATE TABLE User(Name text);").Exec()
_, _ = s.Raw("CREATE TABLE User(Name text);").Exec()
result, _ := s.Raw("INSERT INTO User(`Name`) values (?), (?)", "Tom", "Sam").Exec()
count, _ := result.RowsAffected()
fmt.Printf("Exec success, %d affectedn", count)
}
Steps Taken:
-
Cloned the repo from Github (contained
go.mod
) -
Tried
git mod tidy
to fix “geeorm” err
I tried go mod tidy
in the folder day1-database-sql
, which successfully let the underline below module geeorm
disappeared, but in day1-database-sqlcmd_testmain.go
it is still there.
- Tried
go get github.com/mattn/go-sqlite3
incodego7days-golanggee-ormday1-database-sql
When I tried to reproduce this issue, it turned out the connection to Github is failed… I guess it is because I’m in China. I vaguely remember VSC recommended me to try update go-sqlite3
version to the latest, or something like that.
None of the above seems to have substantive effects on the problem.
- Tried
go mod vendor
However, doc.go
in folder vendor
reported “No packages found for open file V:codego7days-golanggee-ormday1-database-sqlvendorgithub.commattngo-sqlite3doc.go.”
Besides, my VSC constantly reports “Your Code installation appears to be corrupt”, I am not sure if it is a relevent issue but simply print “hello world” is ok in my circumstance.
Chen Zewei is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.