Cover page by David Chisnall

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

12. Accessing Files and the Environment

If you’re going to write any nontrivial Go code, eventually you will get to the point where you need to interact with things outside of your program. The most common mechanism for persistent storage on modern systems is the filesystem, and it’s quite rare to see a program that doesn’t need to read files, even if it isn’t writing any.

If you want to write portable code, the filesystem is one of the more tricky areas that you have to deal with. Any modern operating system provides a file store, which is a mapping from filenames to sequences of bytes. Beyond that, the semantics can vary considerably.

Manipulating Paths

 1  package main 2  import "fmt" 3  import "path" 4  import ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required