Avatar ·

How to get the path to the directory of the current executable in Go?

Hello colleagues! I'm new to Go and ran into a problem that seems elementary but just won't work. I need to find out at runtime the directory where the current executable file (compiled .exe or binary) is located. The problem is that I'm writing a utility for working with configuration files. The project structure is like this: next to the binary there is a configs folder, inside which is config.yaml. I want the program to read this file without using hardcoded paths, because the user can copy the binary to any location. Here's my current code that doesn't work: ```go package main import ( "fmt" "os" "path/filepath" ) func main() { // Trying different options exe, _ := os.Executable() fmt.Println("Executable path:", exe) ```