Back to cheatsheets

Go

GetCurrentDir

Golang: Get current working direactory path.

import (
    "os"
    "fmt"
)
 
func GetCurrentDir() string {
	dir, err := os.Getwd()
	if err != nil {
		fmt.Println(err)
		os.Exit(-1)
	}
 
	return dir
}