Finding Files Relative to the Source File in Go
Unlike interpreted languages, Go programs are compiled and the source file is not required for execution. Therefore, the concept of locating files relative to the source file, as seen in Ruby with __FILE__, is not applicable in Go.
Instead, Go provides the runtime.Caller function, which returns the filename at the time of compilation. However, this information is not always useful for dynamically locating files.
If you have a specific reason for needing to find files relative to the source file, please describe your use case. We may be able to suggest alternative solutions or provide guidance on accessing the necessary information.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3