title: Is there a Go implementation of fs.ReadDir for Google Cloud Storage?
body: <p>I am creating a web application in Go.</p>
  <p>I have modified my working code so that it can read and write files on both a local filesystem and a bucket of Google Cloud Storage based on a flag.</p>
  <p>Basically I included a small package in the middle, and I implemented my-own-pkg.readFile or my-own-pkg.WriteFile and so on...</p>
  <p>I have replaced all calls in my code where I read or save files from the local filesystem with calls to my methods.</p>
  <p>Finally these methods include a simple switch case that runs the standard code to read/write locally or the code to read/wrote from/to a gcp bucket.</p>
  <p><strong>My current problem</strong>
  In some parts I need to perform a ReadDir to get the list of DirEntries and then cycle though them. I do not want to change my code except for replacing os.readDir with my-own-pkg.ReadDir.</p>
  <p>So far I understand that there is not a native function in the gcp module. So I suppose (but here I need your help because I am just guessing) that I would need an implementation of fs.FS for the gcp. It being a new feature of go 1.6 I guess it's too early to find one.</p>
  <p>So I am trying to create simply a my-own-pkg.ReadDir(folderpath) function that does the following:</p>
  <ol>
  <li>case &quot;local&quot;: { }</li>
  <li>case &quot;gcp&quot;: {</li>
  </ol>
  <p>&lt;Use gcp code sample to list objects in my bucket with Query.Prefix = folderpath and
  Query.Delimiter=&quot;/&quot;</p>
  <p>Then create a slice of my-own-pkg.DirEntry (because fs.DkrEntry is just an interface and so it needs to be implemented... :-( ) and return them.</p>
  <p>In order to do so I need to implement also the interface fs.DirEntry (which requires the implementation of interface for FileInfo and maybe something else...)</p>
  <p><strong>Question 1)</strong> is this the right path to follow to solve my issue or is there a better way?</p>
  <p><strong>Question 2)</strong> (only) if so, does the gcp method that lists object with a prefix and a delimiter return just files? I can't see a method that returns also the list of prefixes found</p>
  <p>(If I have prefix/file1.txt and prefix/a/file2.txt I would like to get both &quot;file1.txt&quot; and &quot;a&quot; as files and prefixes...)</p>
  <p>I hope I was enough clear... This time I can't include code because it's incomplete... But in case it helps I can paste what I can.</p>
  <p>NOTE: by the way go 1.6 allowed me to solve elegantly a similar issue when dealing with assets either embedded or on the filesystem thanks to the existing implementation of fs.FS and the related ReadDirFS. So good if I could follow the same route </p>
  <p>By the way I am going on studying and experimenting so in case I am successful I will contribute as well :-)</p>