gogo-playground

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


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?


Solution

  • 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