Open a file in the same directory as the .go source file in Go
go
Solution
Go is not an interpreted language so looking for a file in the same location as the source file doesn't make any sense. The go binary is compiled and the source file doesn't need to be present for the binary to run. Because of that Go doesn't come with an equivalent to FILE. The runtime.Caller function returns the file name at the time the binary was compiled.
I think perhaps if we understood why you actually wanted this functionality we could advise you better.
Problem
When in a source file $PWD/dir/src.go I use ``` os.Open("myfile.txt") ``` it looks for myfile.txt in $PWD (which looks normal). Is there way to tell Go to look for myfile.txt in the same directory as src.go ? I need something like `__FILE__` in Ruby.