// Copyright 2020 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package fsimport ()// ReadDirFS is the interface implemented by a file system// that provides an optimized implementation of ReadDir.typeReadDirFSinterface {FS// ReadDir reads the named directory // and returns a list of directory entries sorted by filename.ReadDir(name string) ([]DirEntry, error)}// ReadDir reads the named directory// and returns a list of directory entries sorted by filename.//// If fs implements ReadDirFS, ReadDir calls fs.ReadDir.// Otherwise ReadDir calls fs.Open and uses ReadDir and Close// on the returned file.func ( FS, string) ([]DirEntry, error) {if , := .(ReadDirFS); {return .ReadDir() } , := .Open()if != nil {returnnil, }defer .Close() , := .(ReadDirFile)if ! {returnnil, &PathError{Op: "readdir", Path: , Err: errors.New("not implemented")} } , := .ReadDir(-1)sort.Slice(, func(, int) bool { return [].Name() < [].Name() })return , }// dirInfo is a DirEntry based on a FileInfo.typedirInfostruct {fileInfoFileInfo}func ( dirInfo) () bool {return .fileInfo.IsDir()}func ( dirInfo) () FileMode {return .fileInfo.Mode().Type()}func ( dirInfo) () (FileInfo, error) {return .fileInfo, nil}func ( dirInfo) () string {return .fileInfo.Name()}func ( dirInfo) () string {returnFormatDirEntry()}// FileInfoToDirEntry returns a DirEntry that returns information from info.// If info is nil, FileInfoToDirEntry returns nil.func ( FileInfo) DirEntry {if == nil {returnnil }returndirInfo{fileInfo: }}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.