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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助