23.8 fs.FS: The Abstract File System Interface
Right, let’s talk about fs.FS. You’ve probably been knee-deep in os.Open and ioutil.ReadAll (or its modern equivalents) for so long that the idea of a filesystem interface sounds either obvious or like academic nonsense. Trust me, it’s the former, and it’s one of the best ideas Go has had in years. It solves a problem you didn’t know you had: being locked into the actual OS filesystem. Think of fs.FS as a contract. It’s an interface that says, “I don’t care where your files live—on a disk, in memory, in a ZIP file, or on the moon. If you can give me a way to open a file by name and read it, you fulfill the contract.” This abstraction is the secret sauce that makes text/template or html/template able to read from your hard drive or an embedded set of files without changing a line of their code. They just take an fs.FS.