func checkErr(err error) {
if err != nil {panic(err)
}
}
// 获取以后的执行门路
//C:\Users\Vic\AppData\Local\Temp\
func getCurrentPath() string {s, err := exec.LookPath(os.Args[0])
checkErr(err)
i := strings.LastIndex(s, "\\")
path := string(s[0 : i+1])
return path
}
// 获取以后文件的具体门路
//D:/Go/workspace/port/network_learn/server/server.go
func CurrentFile() string {_, file, _, ok := runtime.Caller(1)
if !ok {panic(errors.New("Can not get current file info"))
}
return file
}
func main() {
//D:\Go\workspace\port 以后我的项目的门路
pa,_:=os.Getwd()
path:=getCurrentPath()
filePath:=CurrentFile()
fmt.Println(pa)
fmt.Println(path)
fmt.Println(filePath)
}