我的伪造文件:
FROM golang:1.14
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
错误:
main.go:11:2: cannot find package "github.com/gorilla/mux" in any of:
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/go/src/github.com/gorilla/mux (f
我正在尝试使用docker在golang中部署一个应用程序。
我先试过docker build -t go-k8s .,再试过docker run -it {{image-id}}
# build stage
FROM golang:latest AS builder
RUN mkdir -p /go/src/app
RUN go get github.com/gorilla/mux
WORKDIR /go/src/app
COPY main.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
所以我有下面的代码
package main
import (
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter()
}
当我运行时,它会给出以下错误binapi.go:4:2: no required module provides package github.com/gorilla/mux; to add it: go get github.com/gorilla/mux,如何修复此错误?我已经以各种可能的方式运行go get github.com/gorilla/mux命令,
我正在尝试运行带有这样的Dockerfile的使用库的golang应用程序:
FROM golang:1.12
RUN go get github.com/gorilla/mux && \
go get github.com/gorilla/handlers && \
go get github.com/lib/pq && \
go get github.com/joho/godotenv && \
go get github.com/jinzhu/gorm && \
go get gopkg
我的戈罗特之路:- C:\Go
我已将GOPATH设置为:- C:\Users\kunal\go
但是当我在VS代码中导入模块(如github.com/gorilla/mux)时。VS代码提示我这个错误:-
could not import github.com/gorilla/mux (cannot find package "github.com/gorilla/mux" in any of C:\Go\src\github.com\gorilla\mux (from $GOROOT) C\src\github.com\gorilla\mux (from $GOPATH)
当我在Cygwin中使用以下命令时:
$ go get github.com/gorilla/mux
我收到以下错误:
# cd .; git clone https://github.com/gorilla/mux C:\cygwin64\home\USER\Go\src\github.com\gorilla\mux
Cloning into 'C:\cygwin64\home\USER\Go\src\github.com\gorilla\mux'...
fatal: Invalid path '/home/USER/C:\cygwin64\home\USER\Go\
我写了一个应用程序,当我将go模块添加到我的项目go mod init中并尝试启动go run app.go时,我遇到了一个错误:build command-line-arguments: cannot load github.com/nicksnyder/go-i18n/i18n: module github.com/nicksnyder/go-i18n@latest (v2.0.2+incompatible) found, but does not contain package github.com/nicksnyder/go-i18n/i18n。我该如何处理这个问题呢?
go.mod:
我正在使用gorilla/mux在golang中实现一个API应用程序,这是一个功能强大的库,有助于构建web API。
然而,我需要保留每个客户端的ip地址,我如何才能获得每个访问网站的客户端的ip地址?
代码:
func GetIpAddress(w http.ResponseWriter, r *http.Request){
// Whenever User visits this URL (this function)
// We have to know IP Address of user
output := r.UserAgent()
fmt.Pr
我正在开发一个websocket,最近开始使用race进行一些竞赛条件测试。go run -race serve.go
得到这个结果:
WARNING: DATA RACE
Write at 0x0000019ab4a8 by goroutine 95:
go-api/client.ServeWs()
Previous write at 0x0000019ab4a8 by goroutine 117:
go-api/client.ServeWs()
我正在使用gorilla/mux并将其中一个请求升级到websockets。我不确定它是否是由其他原因引起的,但即使是这个非常简单的设置