How to import specific version of 3rd party library in Go Playground?

huangapple go评论63阅读模式
英文:

How to import specific version of 3rd party library in Go Playground?

问题

让我们假设我想导入 Slack Go 包的版本 v0.11.0

在命令行中,我会执行:go get github.com/slack-go/slack@v0.11.0,但在 Go Playground 中,我只能使用 import。

我尝试了 import "github.com/slack-go/slack@v0.11.0",但是那样并没有起作用。

在 Go Playground 中,我该如何导入 Slack Go 包的 v0.11.0 版本呢?

英文:

Let's say I want to import version v0.11.0 of Slack Go package.

In CLI I would call: go get github.com/slack-go/slack@v0.11.0
but in Go Playground I can only use import.

I've tried import "github.com/slack-go/slack@v0.11.0" but that didn't work.

How can I import version v0.11.0 of Slack Go package in Go Playground?

答案1

得分: 4

你导入的版本由go.mod确定,而go get会修改go.mod,因此在playground示例中包括go.mod

package main

import "github.com/slack-go/slack"

func main() {
	_ = slack.New("YOUR_TOKEN_HERE")
}
-- go.mod --
module play.ground

require github.com/slack-go/slack v0.11.0

https://go.dev/play/p/cBt7MR4Kf03

英文:

The version you import is determined by go.mod, and go get modifies go.mod, so include the go.mod in the playground example.

package main

import "github.com/slack-go/slack"

func main() {
	_ = slack.New("YOUR_TOKEN_HERE")
}
-- go.mod --
module play.ground

require github.com/slack-go/slack v0.11.0

https://go.dev/play/p/cBt7MR4Kf03

huangapple
  • 本文由 发表于 2023年3月6日 23:49:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75652954.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定