鉴于我在使用Docker容器方面有一些经验,所以我决定使用Docker容器创建一个go环境并学习。以下是我的Go网络应用程序的dockerfile。
FROM golang:1.12.0-alpine3.9 as base
ARG GO111MODULE=on
RUN apk update && apk add make bash git
COPY ./app /go/src/app
WORKDIR /go/src/app
RUN go build
COPY ./compose/local/golang/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN go get github.com/oxequa/realize
ENTRYPOINT [ "/entrypoint.sh" ]
CMD ["realize", "start"]
我的go.mod文件
module github.com/rajeshyogeshwar/demoapp
go 1.12
require (
github.com/Sirupsen/logrus v1.0.6
github.com/joho/godotenv v1.3.0
github.com/julienschmidt/httprouter v1.2.0
github.com/lib/pq v1.0.0
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.2.0
)
最后是我的项目文件夹结构
我们可以看到我正在尝试使用httprouter模块,它已在go.mod文件中定义。但是我一直在跟踪错误。
app_1 | [06:46:56][APP] : Install
app_1 | main.go:8:2: cannot find package "github.com/julienschmidt/httprouter" in any of:
app_1 | /usr/local/go/src/github.com/julienschmidt/httprouter (from $GOROOT)
app_1 | /go/src/github.com/julienschmidt/httprouter (from $GOPATH)
因此,如果有人可以指出明显的错误,那就太好了。