登录
首页 >  Golang >  Go问答

go playground 可以导入哪些包?

来源:Golang技术栈

时间:2023-04-28 21:38:00 213浏览 收藏

你在学习Golang相关的知识吗?本文《go playground 可以导入哪些包?》,主要介绍的内容就涉及到golang,如果你想提升自己的开发能力,就不要错过这篇文章,大家要知道编程理论基础和实战操作都是不可或缺的哦!

问题内容

我很难在http://play.golang.org/的 go playground 中找到可以导入哪些包的列表。我试图为ebnf使用(显然是实验性的)包。然而,即使是一个简短的程序也不会从中golang.org导入(第 4 行的导入中断):

package main

import "fmt"
import "golang.org/x/exp/ebnf"

const g = `
Production  = name "=" [ Expression ] "." .
Expression  = Alternative { "|" Alternative } .
Alternative = Term { Term } .
Term        = name | token [ "鈥�" token ] | Group | Option | Repetition .
Group       = "(" Expression ")" .
Option      = "[" Expression "]" .
Repetition  = "{" Expression "}" .`

func main() {
    fmt.Println(g)
}

是否在任何地方都说明只有golang.org/src/中的基础包会导入(如果是这样的话)?

我真的很想玩这个实验包,甚至像currency在操场上那样的非实验补充库。

正确答案

Playground 上的About按钮给出了一些提示:

Playground 可以使用大部分标准库,但有一些例外。

标准库 是指 标准库 的包,它们列在 页面的 标准库 部分下。 “其他 ”部分下列出的包不符合条件(这是您尝试过的 - 包属于“ 其他 ”类别下列出的实验性和已弃用的包)。 __ **** **** ****golang.org/x/exp/ebnf


如果您想了解有关 Playground 实现的更多信息,请阅读以下链接:

围棋博客:围棋操场内部

这是一个详尽的游乐场测试,用于导入所有标准库包以显示它们至少可以被导入,但这并不意味着所有东西( 甚至任何东西 )都可以从它们中合理使用。标准库中唯一出现编译错误的包是runtime/cgo; 出于显而易见的原因,不包含没有可构建 Go 源文件的“包”(因为如果文件夹不包含至少一个可构建的 Go 源文件,则它不是包)

这是Playground Link自己尝试一下。

package main

import (
    _ "archive/tar"
    _ "archive/zip"

    _ "bufio"
    _ "bytes"

    _ "compress/bzip2"
    _ "compress/flate"
    _ "compress/gzip"
    _ "compress/lzw"
    _ "compress/zlib"

    _ "container/heap"
    _ "container/list"
    _ "container/ring"

    _ "crypto"
    _ "crypto/aes"
    _ "crypto/cipher"
    _ "crypto/des"
    _ "crypto/dsa"
    _ "crypto/ecdsa"
    _ "crypto/elliptic"
    _ "crypto/hmac"
    _ "crypto/md5"
    _ "crypto/rand"
    _ "crypto/rc4"
    _ "crypto/rsa"
    _ "crypto/sha1"
    _ "crypto/sha256"
    _ "crypto/sha512"
    _ "crypto/subtle"
    _ "crypto/tls"
    _ "crypto/x509"
    _ "crypto/x509/pkix"

    _ "database/sql"
    _ "database/sql/driver"

    _ "debug/dwarf"
    _ "debug/elf"
    _ "debug/gosym"
    _ "debug/macho"
    _ "debug/pe"
    _ "debug/plan9obj"

    _ "encoding"
    _ "encoding/ascii85"
    _ "encoding/asn1"
    _ "encoding/base32"
    _ "encoding/base64"
    _ "encoding/binary"
    _ "encoding/csv"
    _ "encoding/gob"
    _ "encoding/hex"
    _ "encoding/json"
    _ "encoding/pem"
    _ "encoding/xml"

    _ "errors"
    _ "expvar"
    _ "flag"
    _ "fmt"

    _ "go/ast"
    _ "go/build"
    _ "go/constant"
    _ "go/doc"
    _ "go/format"
    _ "go/importer"
    _ "go/parser"
    _ "go/printer"
    _ "go/scanner"
    _ "go/token"
    _ "go/types"

    _ "hash"
    _ "hash/adler32"
    _ "hash/crc32"
    _ "hash/crc64"
    _ "hash/fnv"

    _ "html"
    _ "html/template"

    _ "image"
    _ "image/color"
    _ "image/color/palette"
    _ "image/draw"
    _ "image/gif"
    _ "image/jpeg"
    _ "image/png"

    _ "index/suffixarray"

    _ "io"
    _ "io/ioutil"

    _ "log"
    _ "log/syslog"

    _ "math"
    _ "math/big"
    _ "math/cmplx"
    _ "math/rand"

    _ "mime"
    _ "mime/multipart"
    _ "mime/quotedprintable"

    _ "net"
    _ "net/http"
    _ "net/http/cgi"
    _ "net/http/cookiejar"
    _ "net/http/fcgi"
    _ "net/http/httptest"
    _ "net/http/httputil"
    _ "net/http/pprof"
    _ "net/mail"
    _ "net/rpc"
    _ "net/rpc/jsonrpc"
    _ "net/smtp"
    _ "net/textproto"
    _ "net/url"

    _ "os"
    _ "os/exec"
    _ "os/signal"
    _ "os/user"

    _ "path"
    _ "path/filepath"

    _ "reflect"
    _ "regexp"
    _ "regexp/syntax"

    _ "runtime"
    // _ "runtime/cgo"  // ERROR: missing Go type information
                        // for global symbol: .dynsym size 60
    _ "runtime/debug"
    _ "runtime/pprof"
    _ "runtime/race"
    _ "runtime/trace"

    _ "sort"
    _ "strconv"
    _ "strings"
    _ "sync"
    _ "sync/atomic"
    _ "syscall"

    _ "testing"
    _ "testing/iotest"
    _ "testing/quick"

    _ "text/scanner"
    _ "text/tabwriter"
    _ "text/template"
    _ "text/template/parse"

    _ "time"
    _ "unicode"
    _ "unicode/utf16"
    _ "unicode/utf8"
    _ "unsafe"
)

func main() {
    println("ok")
}

到这里,我们也就讲完了《go playground 可以导入哪些包?》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于golang的知识点!

声明:本文转载于:Golang技术栈 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>