golang get current working directory code example
Example 1: goland how to print out your current path
package main
import(
"os"
"fmt"
"log"
)
func main() {
dir, err := os.Getwd()
if err != nil || dir == "" {
log.Fatalf("Error: %v", err.Error())
}
log.Printf("Current Working Dir: %v", dir)
}
Example 2: golang get working directory
path, err := os.Getwd()
if err != nil {
log.Println(err)
}
fmt.Println(path)
Example 3: golang get working directory
path, err := os.Executable()
if err != nil {
log.Println(err)
}
fmt.Println(path)