title: Is it possible to get filename where code is called in Golang?
body: <p>I was able to get the full path of the current directory, Now I would like to create a function that will read or get the filename where the code is executed. I am able to get the filename but it is return the original filename where the code is written : </p>
  
  <pre><code>func GetFileName() string {
      _, fpath, _, ok := runtime.Caller(0)
      if !ok {
          err := errors.New("failed to get filename")
          panic(err)
      }
      filename := filepath.Base(fpath)
      // remove extension
      filename = removeExtension(filename)
      return filename + ".log"
  }
  </code></pre>
  
  <p>What I want to do is getting the current fileName where the code is executed like :</p>
  
  <p>I created <code>app.go</code> : </p>
  
  <pre><code>package my
  
  function getCurrentFileName() string {
      // some code here that will return the filename where this code is executed.
  }
  </code></pre>
  
  <p>and then when I call <code>getCurrentFileName()</code> in a different file like <code>hello.go</code> in a different location. it will return <code>hello.go</code>.</p>
  
  <p>I have been stuck here for a while and looking for an answer.</p>