简体   繁体   中英

Go Dep - Missing sub-package "chi/middleware" after dep ensure

Missing middleware subpackage from go-chi after running dep ensure.

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)

my Docker file, i also mounted my code volume inside my docker-compose.yaml file

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"

my Code, is just a basic router to test my docker and dep configuration.

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)
}

My code works fine when using go get. But on dep, it's missing its subpackage.

Since you are on Go 1.12, can you try and see if the issue persists when using go mod (Go 1.11+ Modules) .

$ export GO111MODULE=on                         # manually active module mode
$ cd $GOPATH/src/<project path>                 # e.g., cd $GOPATH/src/you/hello
$ go mod init                  

A go mod init will concert your dep Gopkg.lock file.
And it should detect and fetch your missing dependency.
If that has worked, then run go mod tidy to possibly prune any extraneous requirements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM