O'Reilly logo

The Go Programming Language Phrasebook by David Chisnall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required