我想测试码头并去项目。这是我的码头文件泊坞窗golang包导入错误:导入路径不以主机名开头
FROM golang
ARG app_env
ENV APP_ENV $app_env
COPY ./ /go/src/github.com/user/myProject/app
WORKDIR /go/src/github.com/user/myProject/app
RUN go get ./
RUN go build
CMD if [ ${APP_ENV} = production ]; \
then \
app; \
else \
go get github.com/pilu/fresh && \
fresh; \
fi
EXPOSE 8080
它运行良好。然后我在我的go程序中添加了一个包“testpack”。
package main
import(
"fmt"
"time"
"testpack"
)
var now = time.Now()
var election = time.Date(2016, time.November, 8, 0, 0, 0, 0, time.UTC)
func main() {
//get duration between election date and now
tillElection := election.Sub(now)
//get duration in nanoseconds
toNanoseconds := tillElection.Nanoseconds()
//calculate hours from toNanoseconds
hours := toNanoseconds/3600000000000
remainder := toNanoseconds%3600000000000
//derive minutes from remainder of hours
minutes := remainder/60000000000
remainder = remainder%60000000000
//derive seconds from remainder of minutes
seconds := remainder/1000000000
//calculate days and get hours left from remainder
days := hours/24
hoursLeft := hours%24
fmt.Printf("\nHow long until the 2016 U.S. Presidential election?\n\n%v Days %v Hours %v Minutes %v Seconds\n\n", days, hoursLeft, minutes, seconds)
}
现在我跑=>泊坞窗构建./
我得到一个错误
包testpack:无法识别的导入路径 “testpack”(导入路径不以主机名开头)
我试过Error 'import path does not begin with hostname' when building docker with local package但无法解决
任何帮助表示赞赏。
您的dockerfile中无处添加testpack软件包。 – JimB
COPY ./应该照顾它,因为它只是主文件夹上方的一个文件夹 – ChrisDave
如果'testpack'位于应用程序目录中,则不能作为导入路径。导入路径相对于'$ GOPATH/src' - 请参阅[如何编写Go代码](https://golang.org/doc/code。html) – JimB