我可以将第 3 方包导入 golang 游乐场吗

Can I import 3rd party package into golang playground

我用谷歌搜索但没有得到答案。可能吗?如果是,怎么做?

Go Playground 链接:https://play.golang.org/

自 2019 年 5 月 14 日起,it is now possible (from Brad Fitzpatrick)!

The #golang playground now supports third-party imports, pulling them in via https://proxy.golang.org/

Example: https://play.golang.org/p/eqEo7mqdS9l

Multi-file support & few other things up next.
Report bugs at golang/go issue 31944, or here on the tweeters.

(关于 “多文件”支持,参见,自 2019 年 5 月 16 日起,“": see an example here

netbrain suggests another example:

操场上:

package main

import (
    "fmt"

    "gonum.org/v1/gonum/mat"
)

func main() {
    v1 := mat.NewVecDense(4,[]float64{1,2,3,4})
    fmt.Println(mat.Dot(v1,v1))
}

会给出 '30',使用 mat.NewVecDense() to create a column vector, and mat.Dot() 到 return v1v1

的元素乘积之和

重点是:gonum/mat is not part of the Go Standard Library.


原始答案:

Go Playground 上最完整的文章仍然是“Inside the Go Playground”,其中提到:

None 这些进程支持导入远程包(可以通过 Internet 访问)。
它是一个非常独立的系统(您可以在本地 运行 以及从 play.golang.org 使用它),具有多个存根或伪造的功能,例如网络:

Like the file system, the playground's network stack is an in-process fake implemented by the syscall package.
It permits playground projects to use the loopback interface (127.0.0.1).
Requests to other hosts will fail.


2017 年更新:

您有其他选择:

但他们仍然使用官方的 Go Playground 服务来构建和 运行 Go 代码,因此仍然不允许外部导入。

我自己没有尝试过,但是xiam/go-playground表明这是可能的:

Importing custom packages

Remember that playground users won't be able to install or use packages that are not part of the Go standard library, in case you want to showcase a special package you'll have to create a slightly different docker image on top of the sandbox or the unsafebox...

(后面是如何通过修改 Dockerfile 执行此操作的示例。)

这似乎表明编译是(或至少可以)在自定义沙箱内执行的,如 xiam/go-playground 项目所示,从而使这成为可能(不需要 play.golang.org 作为@VonC 的回答表明)。

如果我有机会自己测试一下,我会更详细地更新这个答案。