...

Source file src/cuelang.org/go/mod/module/dirfs.go

Documentation: cuelang.org/go/mod/module

     1  package module
     2  
     3  import (
     4  	"io/fs"
     5  	"os"
     6  )
     7  
     8  // SourceLoc represents the location of some CUE source code.
     9  type SourceLoc struct {
    10  	// FS is the filesystem containing the source.
    11  	FS fs.FS
    12  	// Dir is the directory within the above filesystem.
    13  	Dir string
    14  }
    15  
    16  // OSRootFS can be implemented by an [fs.FS]
    17  // implementation to return its root directory as
    18  // an OS file path.
    19  type OSRootFS interface {
    20  	fs.FS
    21  
    22  	// OSRoot returns the root directory of the FS
    23  	// as an OS file path. If it wasn't possible to do that,
    24  	// it returns the empty string.
    25  	OSRoot() string
    26  }
    27  
    28  // OSDirFS is like [os.DirFS] but the returned value implements
    29  // [OSRootFS] by returning p.
    30  func OSDirFS(p string) fs.FS {
    31  	return dirFSImpl{
    32  		augmentedFS: os.DirFS(p).(augmentedFS),
    33  		osRoot:      p,
    34  	}
    35  }
    36  
    37  var _ interface {
    38  	augmentedFS
    39  	OSRootFS
    40  } = dirFSImpl{}
    41  
    42  type augmentedFS interface {
    43  	fs.FS
    44  	fs.StatFS
    45  	fs.ReadDirFS
    46  	fs.ReadFileFS
    47  }
    48  
    49  type dirFSImpl struct {
    50  	osRoot string
    51  	augmentedFS
    52  }
    53  
    54  func (fsys dirFSImpl) OSRoot() string {
    55  	return fsys.osRoot
    56  }
    57  

View as plain text