首页  >  文章  >  后端开发  >  哪些 Go 标准库包可以在 Go Playground 中导入,是否有限制?

哪些 Go 标准库包可以在 Go Playground 中导入,是否有限制?

Susan Sarandon
Susan Sarandon原创
2024-11-21 05:31:10317浏览

Which Go standard library packages are importable in the Go Playground, and are there limitations?

Go Playground 中允许的包

Go Playground 允许导入标准库的大多数包,但有一些值得注意的例外:

受限软件包:

  • 软件包页面“其他”部分下列出的软件包(例如 golang.org/x/exp/ebnf)不可导入。

额外注意事项:

  • 只能导入带有可构建的 Go 源文件的包。
  • 即使可以导入的包也可能由于限制而无法在 Playground 中完全使用。环境。

导入的广泛测试包:

以下 Playground 测试从标准库中详尽导入所有包。这表明它们可以导入,但并不保证可以使用这些包中的所有甚至任何功能。

Playground 测试:

package main

import (
    // Import all packages from the standard library.
    _ "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")
}

注意: 在此测试中唯一导致错误的包是runtime/cgo,它缺少一个或多个全局的Go类型信息符号。

以上是哪些 Go 标准库包可以在 Go Playground 中导入,是否有限制?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn