go 获取当前路径
- runtime 表示调用该方法的路径,就是谁调用了runtime.Caller所在的方法的路径,返回的路径是唯一的
_, file, _, ok := runtime.Caller(1)
- exec.LookPath 表示执行程序的路径
s, _ := exec.LookPath(os.Args[0])
- go run 直接运行
- go build 后运行
- filepath.Dir 表示执行程序的路径 跟2有点区别不包含程序
filepath.Dir(os.Args[0])
- go run 直接运行
- go build 后运行
- str, _ := os.Getwd() 表示当前的路径 相当于$PWD
str, _ := os.Getwd()