O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

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

How to do it...

  1. Open the console and create the folder chapter01/recipe05.
  2. Navigate to the directory.
  3. Create the main.go file with the following content:
        package main        import (          "fmt"          "os"          "path/filepath"        )        func main() {          ex, err := os.Executable()          if err != nil {            panic(err)          }          // Path to executable file          fmt.Println(ex)          // Resolve the direcotry          // of the executable          exPath := filepath.Dir(ex)          fmt.Println("Executable path :" + exPath)           // Use EvalSymlinks to get          // the real path.          realPath, err := filepath.EvalSymlinks(exPath)          if err != nil {            panic(err)          }          fmt.Println("Symlink evaluated:" + realPath)        }
  1. Build the binary by the command go build -o binary.
  2. Execute the binary by the Terminal call ./binary.
  3. See the output. It should display the absolute ...

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