How to get the directory of the currently running file?

后端 未结 10 519
日久生厌
日久生厌 2020-11-30 16:38

In nodejs I use __dirname . What is the equivalent of this in Golang?

I have googled and found out this article http://andrewbrookins.com/tech/golang-get-directory-o

10条回答
  •  离开以前
    2020-11-30 17:14

    Gustavo Niemeyer's answer is great. But in Windows, runtime proc is mostly in another dir, like this:

    "C:\Users\XXX\AppData\Local\Temp"
    

    If you use relative file path, like "/config/api.yaml", this will use your project path where your code exists.

提交回复
热议问题