How to do it...

These steps cover writing and running your application:

  1. From your terminal/console application, create a new directory called chapter1/filedirs.
  2. Navigate to this directory.
  3. Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter1/filedirs, or use this as an exercise to write some of your own code!
  4. Create a file called dirs.go with the following contents:
        package filedirs                import (                "errors"                "io"                "os"        )                // Operate manipulates files and directories        func Operate() error {                // this 0777 is similar to what you'd see with chown                // on a command line this will create a director                 // /tmp/example, you may also use an absolute path                 // instead of a relative one if err := os.Mkdir("example_dir", os.FileMode(0755)); ...

Get Go Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.