简体   繁体   English

go 不需要模块提供 package 多路复用器错误

[英]go no required module provides package mux error

so I have the following code,所以我有以下代码,

package main
import (
    "github.com/gorilla/mux"
)
func main() {
    router := mux.NewRouter()
}

when I do go run., it gives the following error binapi.go:4:2: no required module provides package github.com/gorilla/mux; to add it: go get github.com/gorilla/mux when I do go run., it gives the following error binapi.go:4:2: no required module provides package github.com/gorilla/mux; to add it: go get github.com/gorilla/mux binapi.go:4:2: no required module provides package github.com/gorilla/mux; to add it: go get github.com/gorilla/mux , how do I fix this error? binapi.go:4:2: no required module provides package github.com/gorilla/mux; to add it: go get github.com/gorilla/mux ,我该如何解决这个错误? I have run the go get github.com/gorilla/mux command in every way possible and im sure it is installed.我已经以各种可能的方式运行了 go get github.com/gorilla/mux 命令,并且我确定它已安装。 I found a post a while back but the command it gave didn't work.不久前我发现了一个帖子,但它给出的命令不起作用。 The command was go env -w GO111MODULE=auto but it didnt solve the issue.该命令是 go env -w GO111MODULE=auto 但它没有解决问题。

here is the go env这是 go 环境

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ProfMonkey07/Library/Caches/go-build"
GOENV="/Users/ProfMonkey07/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ProfMonkey07/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ProfMonkey07/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/ProfMonkey07/binapi/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8g/ssbpssj956ncjflh7w2k4w5m0000gn/T/go-build2892181555=/tmp/go-build -gno-record-gcc-switches -fno-common"

Sounds like you do not have a go.mod file in the root of your project.听起来您在项目的根目录中没有go.mod文件。 Run go mod init <name> first.首先运行go mod init <name>

Then when you run a go mod tidy it will add the "github.com/gorilla/mux"-dependency into the list of required modules, or manually add it with the stated go get github.com/gorilla/mux .然后,当您运行go mod tidy时,它会将“github.com/gorilla/mux”依赖项添加到所需模块的列表中,或者使用所述go get github.com/gorilla/mux
This behavior has changed in go1.16 .这种行为在 go1.16中发生了变化。 Before it would automatically add the dependencies for you.在它会自动为您添加依赖项之前。

Make sure to commit both the go.mod and go.sum files should you use a VCS.如果您使用 VCS,请确保同时提交go.modgo.sum文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 构建 Go docker 图像时“不需要模块提供包” - 'No required module provides package' when building Go docker image 运行 go get 后没有需要的模块提供 package - No required module provides package after running go get Golang:不需要模块提供包 - Golang: no required module provides package 没有必需的模块提供包 github.com/aws/aws-sdk-go/aws - no required module provides package github.com/aws/aws-sdk-go/aws 无需模块提供 package SDL2 - no required module provides package SDL2 无需模块提供 package<imported-package> :在当前目录或任何父目录中找不到 go.mod 文件;</imported-package> - no required module provides package <imported-package>: go.mod file not found in current directory or any parent directory; 使用 MUX 包将查询参数传递给 Go HTTP 请求处理程序 - Passing a query parameter to the Go HTTP request handler using the MUX package 如何将GO Gorilla Mux路线拆分为同一包的2个独立文件 - How to split GO Gorilla Mux routes in 2 separate files of the same package 无法导入 fyne.io/fyne/v2/app(没有必需的模块提供包“fyne.io/fyne/v2/app”) - could not import fyne.io/fyne/v2/app (no required module provides package "fyne.io/fyne/v2/app") 为什么Go在Mac(操作系统软件包)Go上提供了不正确的ENV - Why Go provides an incorrect ENV on Mac ( os package ) Go
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM