运行 dep ensure 后缺少 go-chi 的中间件子包。
project-backend | main.go:8:2: cannot find package "github.com/go-chi/chi/middleware" in any of:
project-backend | /go/src/backend/vendor/github.com/go-chi/chi/middleware (vendor tree)
project-backend | /usr/local/go/src/github.com/go-chi/chi/middleware (from $GOROOT)
project-backend | /go/src/github.com/go-chi/chi/middleware (from $GOPATH)
我的 Docker 文件,我还在 docker-compose.yaml 文件中安装了我的代码卷
FROM golang:1.12
WORKDIR /go/src/backend
COPY Gopkg.toml Gopkg.lock ./
RUN go get -u github.com/golang/dep/cmd/dep
COPY . ./
RUN dep ensure
RUN go get github.com/pilu/fresh
CMD [ "fresh" ]
Gopkg.toml
[prune]
go-tests = true
unused-packages = true
non-go = true
[[constraint]]
name = "github.com/go-chi/chi"
version = "4.0.2"
我的代码,只是一个基本的路由器来测试我的 docker 和 dep 配置。
package main
import (
"fmt"
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func main() {
r := chi.NewRouter()
r.Use(middleware.Logger)
port := ":8080"
r.Get("/api", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("API is working!"))
})
format := "\033[1;36m%s\033[0m"
fmt.Printf(format, "Build success, running on port "+port)
http.ListenAndServe(port, r)
}
我的代码在使用 go get 时运行良好。但是在 dep 上,它缺少它的子包。