Go1.16io/fs包以提高测试性能和可测试性-《GO开发知识笔记》

admin 2025-11-04 01:21:42 编程 来源:ZONE.CI 全球网 0 阅读模式
  • io/fs概述及其存在的必要性
  • 测试基于文件系统的代码
  • JIT Test File Creation
  • Pre-Existing File Fixtures
  • 使用 FS
  • 实现 FS
  • 实现 File 接口
  • 使用 FS 进行测试
  • 总结

    io/fs概述及其存在的必要性

    要理解为什么 Go1.16 版本引入io/fs,就必须先要理解 embedding(内嵌)的基本原理。当开发一个工具的时候,嵌入那些日后需要被访问(寻址)的内容涉及到很多方面,但本文仅仅讨论其中之一。对于每个要嵌入静态文件的工具来说,其工作本质都大同小异。当它们运行的时候,每个静态文件都会被转换为字节,放入一个.go文件之中,最后被编译成二进制文件。一旦进行编译,工具本身就必须负责将针对文件系统的调用转换为对一个虚拟文件系统的调用。当运行嵌入了assets静态文件的程序后,代码访问这些文件的方式依然是针对文件系统的调用,我们必须把这种调用转换为一种虚拟调用(因为实际访问的文件内容已被转换为字节,并编译进程序本身)。此时,我们面临一个问题:如何在代码中确定一个调用是针对虚拟的assets还是真实的文件系统?想象一下这样一个工具:它会遍历一个目录,并返回所能找到的所有以.go结尾的文件名称。如果此工具不能和文件系统交互,那么它将毫无用处。现在,假设有一个 web 应用,它内嵌了一些静态文件,比如images, templates, and style sheets等等。那这个 Web 应用程序在访问这些相关assets时应使用虚拟文件系统,而不是真实文件系统。要分辨出这两种不同的调用,就需要引入一个供开发人员使用的 API,该 API 可以指导该工具何时访问虚拟化,何时访问文件系统。这类 API 都各有特色,像早期的嵌入工具 Packr,它使用的就是自定义的 API。

    1. type Box
    2. func Folder(path string) *Box
    3. func New(name string, path string) *Box
    4. func NewBox(path string) *Box
    5. func (b *Box) AddBytes(path string, t []byte) error
    6. func (b *Box) AddString(path string, t string) error
    7. func (b *Box) Bytes(name string) []byte
    8. func (b *Box) Find(name string) ([]byte, error)
    9. func (b *Box) FindString(name string) (string, error)
    10. func (b *Box) Has(name string) bool
    11. func (b *Box) HasDir(name string) bool
    12. func (b *Box) List() []string
    13. func (b *Box) MustBytes(name string) ([]byte, error)
    14. func (b *Box) MustString(name string) (string, error)
    15. func (b *Box) Open(name string) (http.File, error)
    16. func (b *Box) Resolve(key string) (file.File, error)
    17. func (b *Box) SetResolver(file string, res resolver.Resolver)
    18. func (b *Box) String(name string) string
    19. func (b *Box) Walk(wf WalkFunc) error
    20. func (b *Box) WalkPrefix(prefix string, wf WalkFunc) error

    使用自定义 API 的好处就是工具开发者可以完全掌控用户体验。这包括使开发人员更轻松地管理需要在幕后维护的复杂关系。缺点也很明显,那就是使用者需要去学习这种新的 API。其代码也就严重依赖于这种自定义的 API,这使得它们难以随时间升级。另一种方式就是提供一种模拟标准库的 API , Pkger 就是此例之一:

    1. type File interface {
    2. Close() error
    3. Name() string
    4. Open(name string) (http.File, error)
    5. Read(p []byte) (int, error)
    6. Readdir(count int) ([]os.FileInfo, error)
    7. Seek(offset int64, whence int) (int64, error)
    8. Stat() (os.FileInfo, error)
    9. Write(b []byte) (int, error)
    10. }

    这种方式使用已知的、大家都熟悉的 API,会更容易吸引用户,而且也避免了再去学习新的 API 。Go 1.16标准库引入的io/fs包就采用了此种方式,其优点就是使用了用户熟知的 API 接口,因此也就降低了学习成本,使得用户更加容易接受。但有其利必有其弊,虽然使用现有 API 迎合了用户使用习惯、增加了程序的兼容性,但同时也导致了大而复杂的接口。这亦是io/fs所面临的问题,不幸的是,要正确模拟对文件系统的调用,需要很大的接口占用空间,我们很快就会看到。

    测试基于文件系统的代码

    io/fs包不仅仅只是支撑1.16 版本嵌入功能这么简单,它带来的最大便利之一就是丰富了单元测试,它可以让我们编写更加易于测试的文件系统交互方面的代码。除了增加代码的可测试性之外,io/fs还可以帮助我们编写更加易读的测试用例,并且在我们测试文件系统交互代码时拥有不寻常的性能表现。为了更深入地了解io/fs包,我们来实现一段代码,它的功能是遍历一个给定的根目录,并从中搜索以.go结尾的文件。在循环遍历过程中,程序需要跳过一些符合我们预先设定前缀的目录,比如.git , node_modules , testdata等等。我们没必要去搜寻.git , node_modules文件夹,因为我们清楚它们肯定不会包含.go文件。一旦我们找到了符合要求的文件,我们就把文件的路径加入到一个列表中然后继续搜索。

    1. func GoFiles(root string) ([]string, error) {
    2. var data []string
    3. err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
    4. if err != nil {
    5. return err
    6. }
    7. base := filepath.Base(path)
    8. for _, sp := range SkipPaths {
    9. // if the name of the folder has a prefix listed in SkipPaths
    10. // then we should skip the directory.
    11. // e.g. node_modules, testdata, _foo, .git
    12. if strings.HasPrefix(base, sp) {
    13. return filepath.SkipDir
    14. }
    15. }
    16. // skip non-go files
    17. if filepath.Ext(path) != ".go" {
    18. return nil
    19. }
    20. data = append(data, path)
    21. return nil
    22. })
    23. return data, err
    24. }

    这个函数的执行结果将产生一个类似于下面这样的slice

    1. [
    2. "benchmarks_test.go",
    3. "cmd/fsdemo/main.go",
    4. "cmd/fsdemo/main_test.go",
    5. "fsdemo.go",
    6. "fsdemo_test.go",
    7. "mock_file.go",
    8. ]

    我现在提出的问题是:我们该如何测试这段代码?因为这段代码直接和文件系统交互,我们该如何保证在文件系统上呈现一个准确无误的测试场景呢?鉴于测试方法会有很多种,在深入io/fs之前,我们先看一下最常见的两种方法,从而对比一下io/fs能带给我们怎样的便利。

    JIT Test File Creation

    第一个测试文件系统代码的方法就是在运行时刻创建必须的文件夹结构。

    本文将以benchmark的方式呈现单元测试,如此我们就可以对比各种测试方法的性能。这也是为何setup(创建测试用的文件结构)的代码会被包含在基准代码当中,我们基准测试的目标就是setup的过程。在此情况下,各种测试方法都不会改变setup的底层函数。

    1. func BenchmarkGoFilesJIT(b *testing.B) {
    2. for i := 0; i < b.N; i++ {
    3. dir, err := ioutil.TempDir("", "fsdemo")
    4. if err != nil {
    5. b.Fatal(err)
    6. }
    7. names := []string{"foo.go", "web/routes.go"}
    8. for _, s := range SkipPaths {
    9. // ex: ./.git/git.go
    10. // ex: ./node_modules/node_modules.go
    11. names = append(names, filepath.Join(s, s+".go"))
    12. }
    13. for _, f := range names {
    14. if err := os.MkdirAll(filepath.Join(dir, filepath.Dir(f)), 0755); err != nil {
    15. b.Fatal(err)
    16. }
    17. if err := ioutil.WriteFile(filepath.Join(dir, f), nil, 0666); err != nil {
    18. b.Fatal(err)
    19. }
    20. }
    21. list, err := GoFiles(dir)
    22. if err != nil {
    23. b.Fatal(err)
    24. }
    25. lexp := 2
    26. lact := len(list)
    27. if lact != lexp {
    28. b.Fatalf("expected list to have %d files, but got %d", lexp, lact)
    29. }
    30. sort.Strings(list)
    31. exp := []string{"foo.go", "web/routes.go"}
    32. for i, a := range list {
    33. e := exp[i]
    34. if !strings.HasSuffix(a, e) {
    35. b.Fatalf("expected %q to match expected %q", list, exp)
    36. }
    37. }
    38. }
    39. }

    BenchmarkGoFilesJIT测试用例中,我们使用io/ioutil包来为测试创建满足需求场景的临时文件夹和文件。此刻,意味着要创建包含.go文件的node_modules.git目录,以便于确认这些.go文件不会出现在处理结果中。如果GoFiles函数正常工作的话,我们在结果集中将看到两个条目,foo.go 以及 web/routes.go。这种JIT方式有两大缺点:其一,随着时间的推移,编写和维护setup部分的代码将会变得非常麻烦,为测试用例做大量的setup本身也会引入更多的 bug。其二,也是最大的弊端,JIT测试会创建大量的文件和文件夹,这势必会在文件系统上产生大量的i/o竞争和i/o操作,从而让我们的任务性能非常低效。

    1. goos: darwin
    2. goarch: amd64
    3. pkg: fsdemo
    4. cpu: Intel(R) Xeon(R) W-2140B CPU @ 3.20GHz
    5. BenchmarkGoFilesJIT-16 1470 819064 ns/op

    Pre-Existing File Fixtures

    另一种测试GoFiles的方法是创建一个名为testdata的目录,并且在里面创建好测试场景所需的全部文件。

    1. testdata
    2. └── scenario1
    3. ├── _ignore
    4. │ └── ignore.go
    5. ├── foo.go
    6. ├── node_modules
    7. │ └── node_modules.go
    8. ├── testdata
    9. │ └── testdata.go
    10. └── web
    11. └── routes.go
    12. 5 directories, 5 files

    使用这种方法,我们就可以清理掉很多我们的测试代码,让GoFiles函数指向事先准备好的已包含相应测试场景的文件夹。

    1. func BenchmarkGoFilesExistingFiles(b *testing.B) {
    2. for i := 0; i < b.N; i++ {
    3. list, err := GoFiles("./testdata/scenario1")
    4. if err != nil {
    5. b.Fatal(err)
    6. }
    7. lexp := 2
    8. lact := len(list)
    9. if lact != lexp {
    10. b.Fatalf("expected list to have %d files, but got %d", lexp, lact)
    11. }
    12. sort.Strings(list)
    13. exp := []string{"foo.go", "web/routes.go"}
    14. for i, a := range list {
    15. e := exp[i]
    16. if !strings.HasSuffix(a, e) {
    17. b.Fatalf("expected %q to match expected %q", list, exp)
    18. }
    19. }
    20. }
    21. }

    这种方法大大减少了测试的消耗,从而提高了测试的可靠性和可读性。与 JIT 方法相比,此方法呈现的测试速度也快得多。

    1. goos: darwin
    2. goarch: amd64
    3. pkg: fsdemo
    4. cpu: Intel(R) Xeon(R) W-2140B CPU @ 3.20GHz
    5. BenchmarkGoFilesExistingFiles-16 9795 120648 ns/op
    6. BenchmarkGoFilesJIT-16 1470 819064 ns/op

    这种方法的缺点是为 GoFiles 函数创建可靠测试所需的文件/文件夹的数量和组合(意指数量和组合可能都很巨大)。到目前为止,我们仅仅测试了 “成功” 的情况,我们还没有为错误场景或其它潜在的情况编写测试。使用这种方式,一个很常见的问题就是,开发者会逐渐的为多个测试重复使用这些场景(指 testdata 中的测试场景)。随时间推移,开发者并非为新的测试创建新的结构,而是去更改现有的场景以满足新的测试。这将测试全部耦合在了一起,使测试代码变得异常脆弱。使用io/fs重写GoFiles函数,我们将会解决所有的问题!

    使用 FS

    通过上面的了解,我们知道io/fs包支持针对virtual file system的实现(译者注:意指io/fs包提供了很多针对fs.FS的功能)。为了利用io/fs提供的功能,我们可以通过重写GoFiles函数让它接受一个fs.FS作为参数。在正式的代码中,我们可以调用os.DirFS来获得一个由底层文件系统支持的fs.FS接口的实现。为了遍历一个fs.FS的实现,我们需要使用fs.WalkDir函数,fs.WalkDir函数的功能近乎等同于filepath.Walk函数。尽管这些差异很值得推敲一番,但这超出了本文的范围,因此我们将在以后的文章中另行阐述。

    1. func GoFilesFS(root string, sys fs.FS) ([]string, error) {
    2. var data []string
    3. err := fs.WalkDir(sys, ".", func(path string, de fs.DirEntry, err error) error {
    4. if err != nil {
    5. return err
    6. }
    7. base := filepath.Base(path)
    8. for _, sp := range SkipPaths {
    9. // if the name of the folder has a prefix listed in SkipPaths
    10. // then we should skip the directory.
    11. // e.g. node_modules, testdata, _foo, .git
    12. if strings.HasPrefix(base, sp) {
    13. return filepath.SkipDir
    14. }
    15. }
    16. // skip non-go files
    17. if filepath.Ext(path) != ".go" {
    18. return nil
    19. }
    20. data = append(data, path)
    21. return nil
    22. })
    23. return data, err
    24. }

    得益于io/fs包兼容性 API 带来的便利,GoFilesFS函数避免了昂贵的重写,仅需要很小的修改就可完工。

    实现 FS

    现在,该函数已更新为使用fs.FS,让我们看看如何为它编写测试。在此之前,我们先来实现fs.FS

    1. type FS interface {
    2. // Open opens the named file.
    3. //
    4. // When Open returns an error, it should be of type *PathError
    5. // with the Op field set to "open", the Path field set to name,
    6. // and the Err field describing the problem.
    7. //
    8. // Open should reject attempts to open names that do not satisfy
    9. // ValidPath(name), returning a *PathError with Err set to
    10. // ErrInvalid or ErrNotExist.
    11. Open(name string) (File, error)
    12. }

    Open函数接收一个文件的路径,然后返回一个fs.File和一个error。如文档所述,需要满足某些关于错误的需求。对于我们的测试来说,我们将会使用一个模拟文件类型的切片,并稍后将其实现为fs.FS,该切片还将实现所有本次测试所需的功能。

    1. type MockFS []*MockFile
    2. func (mfs MockFS) Open(name string) (fs.File, error) {
    3. for _, f := range mfs {
    4. if f.Name() == name {
    5. return f, nil
    6. }
    7. }
    8. if len(mfs) > 0 {
    9. return mfs[0].FS.Open(name)
    10. }
    11. return nil, &fs.PathError{
    12. Op: "read",
    13. Path: name,
    14. Err: os.ErrNotExist,
    15. }
    16. }

    MockFS.Open中,我们在已知文件列表中循环匹配请求的名称,如果匹配成功则返回该文件;如果没有找到,则尝试在第一个文件中递归打开。最后,如果没有找到,则按文档要求返回适当的error。我们的MockFS目前还未实现完整,我们还需要实现fs.ReadDirFS接口来模拟文件。尽管fs.ReadDirFS文档未提及以下约束,但fs.ReadDirFileFile.ReadDir则需要它们。因此,它们也值得留意和实现。

    1. // ReadDir reads the contents of the directory and returns
    2. // a slice of up to n DirEntry values in directory order.
    3. // Subsequent calls on the same file will yield further DirEntry values.
    4. //
    5. // If n > 0, ReadDir returns at most n DirEntry structures.
    6. // In this case, if ReadDir returns an empty slice, it will return
    7. // a non-nil error explaining why.
    8. // At the end of a directory, the error is io.EOF.
    9. //
    10. // If n <= 0, ReadDir returns all the DirEntry values from the directory
    11. // in a single slice. In this case, if ReadDir succeeds (reads all the way
    12. // to the end of the directory), it returns the slice and a nil error.
    13. // If it encounters an error before the end of the directory,
    14. // ReadDir returns the DirEntry list read until that point and a non-nil error.

    尽管这些规则听起来令人困惑,但实际上,这种逻辑非常简单。

    1. func (mfs MockFS) ReadDir(n int) ([]fs.DirEntry, error) {
    2. list := make([]fs.DirEntry, 0, len(mfs))
    3. for _, v := range mfs {
    4. list = append(list, v)
    5. }
    6. sort.Slice(list, func(a, b int) bool {
    7. return list[a].Name() > list[b].Name()
    8. })
    9. if n < 0 {
    10. return list, nil
    11. }
    12. if n > len(list) {
    13. return list, io.EOF
    14. }
    15. return list[:n], io.EOF
    16. }

    实现 File 接口

    我们已经完成了fs.FS的实现,但仍需要实现一组接口来满足fs包的需要。幸运的是,我们可以将所有接口实现到一个类型当中,从而使我们的测试更加简便。

    继续之前,我要申明一点:我故意没有完全实现接口的文件读取部分,因为这将增加不必要的复杂度,而这些复杂度不是本文所需要的。所以我们将在后续的文章中探讨相关主题。

    为了测试我们的代码,我们将要实现四个接口: fs.File , fs.FileInfo , fs.ReadDirFile , and fs.DirEntry

    1. type File interface {
    2. Stat() (FileInfo, error)
    3. Read([]byte) (int, error)
    4. Close() error
    5. }
    6. type FileInfo interface {
    7. Name() string
    8. Size() int64
    9. Mode() FileMode
    10. ModTime() time.Time
    11. IsDir() bool
    12. Sys() interface{}
    13. }
    14. type ReadDirFile interface {
    15. File
    16. ReadDir(n int) ([]DirEntry, error)
    17. }
    18. type DirEntry interface {
    19. Name() string
    20. IsDir() bool
    21. Type() FileMode
    22. Info() (FileInfo, error)
    23. }

    乍看之下,这些接口的体量之大似乎压人心魄。但是不用多虑,因为它们很多重叠的功能,所以我们可以把他们凝聚到一个类型当中。

    1. type MockFile struct {
    2. FS MockFS
    3. isDir bool
    4. modTime time.Time
    5. mode fs.FileMode
    6. name string
    7. size int64
    8. sys interface{}
    9. }

    MockFile类型包含一个fs.FS的实现MockFS,它将持有我们测试用到的所有文件。MockFile 类型中的其余字段供我们设置为其相应功能的返回值。

    1. func (m *MockFile) Name() string {
    2. return m.name
    3. }
    4. func (m *MockFile) IsDir() bool {
    5. return m.isDir
    6. }
    7. func (mf *MockFile) Info() (fs.FileInfo, error) {
    8. return mf.Stat()
    9. }
    10. func (mf *MockFile) Stat() (fs.FileInfo, error) {
    11. return mf, nil
    12. }
    13. func (m *MockFile) Size() int64 {
    14. return m.size
    15. }
    16. func (m *MockFile) Mode() os.FileMode {
    17. return m.mode
    18. }
    19. func (m *MockFile) ModTime() time.Time {
    20. return m.modTime
    21. }
    22. func (m *MockFile) Sys() interface{} {
    23. return m.sys
    24. }
    25. func (m *MockFile) Type() fs.FileMode {
    26. return m.Mode().Type()
    27. }
    28. func (mf *MockFile) Read(p []byte) (int, error) {
    29. panic("not implemented")
    30. }
    31. func (mf *MockFile) Close() error {
    32. return nil
    33. }
    34. func (m *MockFile) ReadDir(n int) ([]fs.DirEntry, error) {
    35. if !m.IsDir() {
    36. return nil, os.ErrNotExist
    37. }
    38. if m.FS == nil {
    39. return nil, nil
    40. }
    41. return m.FS.ReadDir(n)
    42. }

    Stat() (fs.FileInfo, error)方法可以返回MockFile本身,因为它已经实现了fs.FileInfo接口,此为我们如何用一个MockFile类型实现众多所需的接口的一个例证!

    使用 FS 进行测试

    鉴于我们已经拥有了MockFSMockFile,那么是时候为GoFilesFS函数编写测试了。依例,我们首先要为测试设置文件夹和文件结构。通过两个辅助函数NewFileNewDir、以及使用切片直接构建一个fs.FS(指 MockFS)的便捷性,我们可以在内存中快速的构建出复杂的文件夹和文件结构。

    1. func NewFile(name string) *MockFile {
    2. return &MockFile{
    3. name: name,
    4. }
    5. }
    6. func NewDir(name string, files ...*MockFile) *MockFile {
    7. return &MockFile{
    8. FS: files,
    9. isDir: true,
    10. name: name,
    11. }
    12. }
    13. func BenchmarkGoFilesFS(b *testing.B) {
    14. for i := 0; i < b.N; i++ {
    15. files := MockFS{
    16. // ./foo.go
    17. NewFile("foo.go"),
    18. // ./web/routes.go
    19. NewDir("web", NewFile("routes.go")),
    20. }
    21. for _, s := range SkipPaths {
    22. // ex: ./.git/git.go
    23. // ex: ./node_modules/node_modules.go
    24. files = append(files, NewDir(s, NewFile(s+".go")))
    25. }
    26. mfs := MockFS{
    27. // ./
    28. NewDir(".", files...),
    29. }
    30. list, err := GoFilesFS("/", mfs)
    31. if err != nil {
    32. b.Fatal(err)
    33. }
    34. lexp := 2
    35. lact := len(list)
    36. if lact != lexp {
    37. b.Fatalf("expected list to have %d files, but got %d", lexp, lact)
    38. }
    39. sort.Strings(list)
    40. exp := []string{"foo.go", "web/routes.go"}
    41. for i, a := range list {
    42. e := exp[i]
    43. if e != a {
    44. b.Fatalf("expected %q to match expected %q", list, exp)
    45. }
    46. }
    47. }
    48. }

    本次setup的代码非常简单高效地完成了我们所需的工作,如果我们需要在测试中增加文件或文件夹,可以通过插入一行或两行来迅速完成。更重要的是,在尝试编写测试时,我们不会因复杂的setup代码而分心。

    1. BenchmarkGoFilesFS-16 432418 2605 ns/op

    总结

    使用BenchmarkGoFilesJIT方式,我们有很多直接操作filesystem的文件setupteardown代码(译者注:指文件结构的创建和销毁),这会让测试代码本身引入很多潜在的errorbugsetupteardown代码会让测试的重心偏移,其复杂性使得很难对测试方案进行更改。而且,这种方式的基准测试性能最差。不同的是,BenchmarkGoFilesExistingFiles方式使用预先在testdata中准备好的文件结构场景。这使得测试过程不再需要setup代码,仅仅需要为测试代码指明场景在磁盘中的位置。这种方式还有其它便利之处,例如其使用的是可以用标准工具轻松编辑和操纵的真实文件。与JIT方式相比,因其使用了已存在的场景数据,这极大地增加了测试的性能。其成本是需要在repo中创建和提交很多的场景数据,而且这些场景数据很容易被其他的测试代码滥用,最终导致测试用例变得脆弱不堪。这两种方式都有其它的一些缺陷,比如难以模拟大文件、文件的权限、错误等等,而io/fs,可以帮我们解决这些问题!我们已经看到了如何通微小的代码改动来使用io/fs包,得益于此,我们的测试代码变得更易于编写。这种方式不需要teardown代码,设置场景数据就像为切片追加数据一样简单,测试中的修改也变得游刃有余。我们的MockFile类型可以让我们像MockFS类型一样模拟出文件的大小、文件的权限、错误甚至更多。最重要的是,我们看到,通过使用 io / fs 并实现其接口,与 JIT 测试相比,我们可以将文件系统测试的速度提高 300%以上。

    1. goos: darwin
    2. goarch: amd64
    3. pkg: fsdemo
    4. cpu: Intel(R) Xeon(R) W-2140B CPU @ 3.20GHz
    5. BenchmarkGoFilesFS-16 432418 2605 ns/op
    6. BenchmarkGoFilesExistingFiles-16 9795 120648 ns/op
    7. BenchmarkGoFilesJIT-16 1470 819064 ns/op

    虽然本文介绍了如何使用新的io/fs包来增强我们的测试,但这只是该包的冰山一角。比如,考虑一个文件转换管道,该管道根据文件的类型在文件上运行转换程序。再比如,将.md 文件从 Markdown 转换为 HTML,等等。使用io/fs包,您可以轻松创建带有接口的管道,并且测试该管道也相对简单。 Go 1.16 有很多令人兴奋的地方,但是,对我来说,io/fs包是最让我兴奋的一个。

    以太坊cppgolang区别 编程

    以太坊cppgolang区别

    以太坊是一种去中心化的开源平台,它采用智能合约技术,旨在构建和运行不受干扰的分布式应用程序。作为目前最受欢迎的区块链平台之一,以太坊提供了多种编程语言的支持,其
    progolang 编程

    progolang

    Go语言(Golang)是由Google开发的一门静态类型编程语言。作为一名专业的Golang开发者,我深知这门语言的优势和特点。在本文中,我将介绍Golang
    golangn个发送者 编程

    golangn个发送者

    Golang是一种开源的编程语言,由Google团队开发,旨在提高程序的并发性和简化软件开发过程。在Go语言中,有时需要向多个接收者发送信息。本文将介绍如何在G
    golang技能图谱 编程

    golang技能图谱

    从互联网行业的快速发展到人工智能技术的日益成熟,各种编程语言也应运而生。而在这众多的编程语言中,Golang(即Go)作为一门强大且高效的开发语言备受关注。Go
    评论:0   参与:  10