从github导入包的问题

问题描述 投票:0回答:0
import (
    "html/template"
    "log"
    "net/http"

    "github.com/jmoiron/sqlx"
)

在这里,我导入包以使程序正常工作。 VS 代码返回这个问题

could not import github.com/jmoiron/sqlx (cannot find package "github.com/jmoiron/sqlx" in any of 
    C:\Program Files\Go\src\github.com\jmoiron\sqlx (from $GOROOT)
    C:\Users\USER\go\src\github.com\jmoiron\sqlx (from $GOPATH))

请向我解释问题并提出一些可能的解决方案

我已经尝试找到解决方案并访问了此页面:

如何导入vscode路径

Golang build error: cannot assign *sqlx.DB to *sql.DB

https://go.dev/doc/code#ImportingRemote

可能是相对 GOPATH 有问题,第二页有些人告诉我们使用绝对路径。我不知道如何使用绝对路径导入

我还写了 go mod init * path to file * 和 go mod tidy 这是什么终端返回


$ go mod init cmd/blog
go: to add module requirements and sums:
        go mod tidy

$ go mod tidy
go: finding module for package github.com/jmoiron/sqlx
go: finding module for package github.com/go-sql-driver/mysql
go: found github.com/go-sql-driver/mysql in github.com/go-sql-driver/mysql v1.7.0
go: found github.com/jmoiron/sqlx in github.com/jmoiron/sqlx v1.3.5

go importerror
© www.soinside.com 2019 - 2024. All rights reserved.