简体   繁体   中英

How can I tell which version of a dependency was pulled?

In main.go I have this import statement:

import (
    "fmt"
    "log"
    "os"
    "os/signal"
    "strings"
    "syscall"
    "github.com/bwmarrin/discordgo"
)

And I'm running into a bug that is supposed to be fixed in the more recent versions of this dependency. How can I determine what version was pulled in when I built my docker container that I deployed?

In GoLand it doesn't show any external dependencies:

在此处输入图片说明

Here's my Dockerfile:

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

ENV CGO_ENABLED=0
ENV GO111MODULE=off

# Fetch application dependencies
RUN apk add --no-cache --update git \
    && go get github.com/bwmarrin/discordgo \
    && go get github.com/jonas747/dshardmanager \
    && go get github.com/bugsnag/bugsnag-go \
    && apk del git

# Build binary
RUN go build -o main .

CMD ["/app/main"]

There's a couple ways you can go about this. When you run go get remote/path/to/lib , it installs that to $GOPATH/src/remote/path/to/lib , so if you cd into that path and run git describe --tags , you'll see the latest version pulled. However, if you manage your project with go modules, you should be able to see the version you're using in the go.mod file after the dependency name.

So, in essence: go get github.com/bwmarrin/discordgo && cd $GOPATH/src/github.com/bwmarrin/discordgo && git describe --tags should be the quick and dirty way to find what version you're using for this specific scenario.

If you want an updated version of your package try using go get -u <package>

Or maybe use dependency management such as dep . ( https://github.com/golang/dep ) You can specify your versions in your Gopkg.toml .

Or go modules if you are using version 1.11 or higher for golang.

I see your GoLand SDK is in different version with your Docker. If you use 1.12, you can try to use go module. It will generate a file go.mod, which will describe your package and version, and better management. For example:

module github.com/example

require (
    github.com/Azure/azure-storage-blob-go v0.0.0-20190104215108-45d0c5e3638e
    github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23
    github.com/gorilla/context v1.1.1 // indirect
    github.com/gorilla/mux v1.6.2
    github.com/patrickmn/go-cache v2.1.0+incompatible
    github.com/prometheus/client_golang v0.9.2
    github.com/sirupsen/logrus v1.3.0
    golang.org/x/net v0.0.0-20181220203305-927f97764cc3
    golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
    golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e // indirect
    gopkg.in/resty.v1 v1.12.0
)

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