Go Playground 提供了一個方便的測試 Go 程式碼片段的環境。但是,對於可以在 Playground 中匯入哪些套件有一定的限制。
Playground 中的「關於」按鈕包含以下資訊:
「Playground 可以使用大部分標準庫,但也有一些例外。」
此聲明澄清了來自標準庫的套件通常可以導入,但不是全部。
標準庫包列在「包」頁面的「標準庫」部分下。但是,「其他」部分下列出的軟體包(例如 golang.org/x/exp/ebnf)無法在 Playground 中匯入。
Playground 的導入限制主要是出於安全性和功能的考量。導入外部套件會帶來安全風險和效能問題,尤其是在 Playground 不受限制的環境中。
為了演示標準庫包的可導入性,以下程式碼片段導入標準庫中的每個包(不包括那些沒有可構建的Go 源文件的包):
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/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") }
在Playground 中嘗試看看可導入包的詳盡列表。
以上是哪些標準庫包在 Go Playground 中受到限制,為什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!