Say I have a file:
i_want_this_name.go:
package main func main(){ filename := some_func() // should be "i_want_this_name" }
How to get executable name in go?
The command name can be found in the os.Args[0]as status in the documentation for the os package :
os.Args[0]
var Args []stringArgs contain command line arguments starting with the program name.
var Args []string
Args contain command line arguments starting with the program name.
To use it, do the following:
package main import "os" func main(){ filename := os.Args[0] }
This should work for you:
package main import ( "fmt" "runtime" ) func main() { _, fileName, lineNum, _ := runtime.Caller(0) fmt.Printf("%s: %d\n", fileName, lineNum) }
Source: https://habr.com/ru/post/1609254/More articles:Types try to check with oauth - pythonIs there a way to automatically initialize a variable if null is javaReact is dangerous. SetInnerHtml does not work under certain conditions - javascriptRepeat light element dom - polymerPolymer 1.0 dynamic template with dom-repeat - javascriptCreating a fake or dummy pid in an elixir - processWhy did I get FATAL EXCEPTION when I tested the MediaRecorder sample? - androidshell_exec (), some hosts disabled it by default, looking for a walk - phpSimple Polymer 1.0 Datasheet - javascriptAngularJS - directive for creating a conditional button, cascading all attributes - javascriptAll Articles