Skip to content

Instantly share code, notes, and snippets.

@leafsummer
Created May 14, 2019 09:56
Show Gist options
  • Save leafsummer/c0076de6493215c10cd8d13976537dba to your computer and use it in GitHub Desktop.
Save leafsummer/c0076de6493215c10cd8d13976537dba to your computer and use it in GitHub Desktop.
[GetCwd]
package main
import (
"path/filepath"
"fmt"
"os"
"strings"
"log"
)
func GetCwd() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
return strings.Replace(dir, "\\", "/", -1)
}
func main() {
var (
cwd string
)
cwd = GetCwd()
fmt.Printf("CWD is %s\n", cwd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment