go获取当前执行的位置程序

func getCurrentPath() string {
    _, filename, _, ok := runtime.Caller(1)
    var cwdPath string
    if ok {
        cwdPath = path.Join(path.Dir(filename), "") // the the main function file directory
    } else {
        cwdPath = "./"
    }
    return cwdPath
}

 

posted @ 2019-04-12 14:42  wujf  阅读(1338)  评论(0编辑  收藏  举报