You are previewing The Go Programming Language Phrasebook.

The Go Programming Language Phrasebook

Cover of The Go Programming Language Phrasebook by David Chisnall Published by Addison-Wesley Professional
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 ...

The best content for your career. Discover unlimited learning on demand for around $1/day.