English 中文(简体)
如何以最佳方式在运行期间找到可起诉的道路?
原标题:What s the best way to get the path of the executable during runtime?
  • 时间:2010-05-11 21:31:11
  •  标签:
  • go

如果能以不同的方式(时间、大概等)执行我的行程,那么在一段时期内,获得载有可起诉的行文的目录的最可靠方式是什么?

简言之,这可变:

os.path.realpath(__file__)
最佳回答

换句话说,它可能与C一样,即没有一种可移动的无ool方法。 见How,我没有发现C可起诉的地点?

问题回答

: How to Get the Directory of the Currentfile/a>:

I eventually found out about runtime.Caller().
This returns a few details about the current goroutine’s stack, including the file path.

The context of my problem was opening a data file in a shared package.
What I cooked up was:

_, filename, _, _ := runtime.Caller(1)
f, err := os.Open(path.Join(path.Dir(filename), "data.csv"))

我发现的最佳方法是使用<条码>。 见以下文件:golang doc





相关问题
minimum work size of a goroutine [closed]

Does anyone know approximately what the minimum work size is needed in order for a goroutine to be beneficial (assuming that there are free cores for the work to be offloaded to)?

How do you get the terminal size in Go?

How do I get the terminal size in Go. In C it would look like this: struct ttysize ts; ioctl(0, TIOCGWINSZ, &ts); But how to i access TIOCGWINSZ in Go

What do you use to write Go [closed]

I know its a bit too early, but I ve been trying out Go (Google s Programming Language) and its kindof annoying to write code in gedit. So, my question: What do you use to experiment with Go?

Shared memory vs. Go channel communication

One of Go s slogans is Do not communicate by sharing memory; instead, share memory by communicating. I am wondering whether Go allows two different Go-compiled binaries running on the same machine to ...

Embedding instead of inheritance in Go

What is your opinion of this design decision? What advantages does it have and what disadvantages? Links: Embedding description

热门标签