gpt4 book ai didi

go - 如何使 golang 的 golang 版本和我的 Dockerfile 保持同步?

转载 作者:IT王子 更新时间:2023-10-29 02:35:21 32 4
gpt4 key购买 nike

我是 goland 的新手,试图在我的第一个项目中使用它。我注意到在 goland 中它没有显示通过容器引入的相同 golang SDK。

这是我的 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"]

但是在goland中你可以看到它没有显示正确的版本。 有没有办法设置它,以便 goland 始终看到容器中使用的版本?

enter image description here

最佳答案

Goland 使用您的 Systems Go SDK,而不是 Dockerfile 中的那个。

如果你转到 Goland > Preferences > Go > Go Root,你会找到 Goland 使用的版本,这将对应于你在 External Libraries Section 中的版本。

在这种情况下,您可能需要更新系统安装的 go 版本以匹配 dockerfile 中的版本。

同样值得注意的是,在开发过程中,Goland 将允许您选择使用哪个版本的 Go 来构建您的项目。在上面提到的相同设置中,您将在 Go 子菜单下看到标题 For Current Project。如果您安装了多个 Go 版本,您可以选择 sdk 并让 Goland 处理构建。

关于go - 如何使 golang 的 golang 版本和我的 Dockerfile 保持同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55782656/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com