How to get the directory of the currently running file?

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

I have googled and found out this article . Where he uses below code

_, filename, _, _ := runtime.Caller(1)
f, err := os.Open(path.Join(path.Dir(filename), "data.csv"))

But is it the right way or idiomatic way to do in Golang?

1 Like

This should do it:

import (

func main() {
    dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
    if err != nil {