doumanju2533 2019-04-21 13:06
浏览 180

如何使用Go模块通过提交哈希或分支拉取依赖项?

I'm trying to upgrade my project to use Go modules for dependency management. I recognize this a new/experimental feature. I'm getting an error: cannot find module providing package.

My go.mod currently reads:

require (
    github.com/bugsnag/bugsnag-go v1.5.1
    github.com/bwmarrin/discordgo v0.19.0
    github.com/jonas747/dshardmanager v0.0.0-20180911185241-9e4282faed43
)

My Dockerfile:

FROM golang:1.12-alpine
RUN mkdir /app
WORKDIR /app
ADD src/ /app

ENV CGO_ENABLED=0

# Building requires git because we're pulling a dependency by commit hash
RUN apk add --no-cache --update git \
    && go build ./... \
    && apk del git

CMD ["/app/main"]

When building, it fails with:

cannot load github.com/bugsnag/panicwrap: cannot find module providing package github.com/bugsnag/panicwrap

When I look at https://github.com/bugsnag/bugsnag-go I don't see a go.mod file. Is this error indicating that this dependency doesn't support modules?

  • 写回答

1条回答 默认 最新

  • dpj96988 2019-04-21 15:16
    关注

    You're doing something wrong, because it works. It does not need a go.mod in order to work with go.mod-based applications:

    nrxr at lise in ~/code/src/github.com/nrxr/stack
    $ go mod init
    go: creating new go.mod: module github.com/nrxr/stack
    
    nrxr at lise in ~/code/src/github.com/nrxr/stack
    $ go get github.com/bugsnag/bugsnag-go
    go: finding github.com/bugsnag/bugsnag-go v1.5.1
    go: downloading github.com/bugsnag/bugsnag-go v1.5.1
    go: extracting github.com/bugsnag/bugsnag-go v1.5.1
    go: finding github.com/bugsnag/panicwrap v1.2.0
    go: downloading github.com/bugsnag/panicwrap v1.2.0
    go: finding github.com/gofrs/uuid v3.2.0+incompatible
    go: downloading github.com/gofrs/uuid v3.2.0+incompatible
    go: extracting github.com/bugsnag/panicwrap v1.2.0
    go: extracting github.com/gofrs/uuid v3.2.0+incompatible
    go: finding github.com/kardianos/osext latest
    go: downloading github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
    go: extracting github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
    
    nrxr at lise in ~/code/src/github.com/nrxr/stack
    $ cat go.mod
    module github.com/nrxr/stack
    
    go 1.12
    
    require (
            github.com/bugsnag/bugsnag-go v1.5.1 // indirect
            github.com/bugsnag/panicwrap v1.2.0 // indirect
            github.com/gofrs/uuid v3.2.0+incompatible // indirect
            github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
    )
    

    Maybe try again? Try with what I just used here.

    评论

报告相同问题?

悬赏问题

  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题