如何定义包级别的文件?

huangapple go评论70阅读模式
英文:

How to define package level files?

问题

我有一个在notifications包中的模板。

/notifications
/html/notify.tpl

问题是,如果我从不同的路径/包中调用该包的函数,程序将无法找到该文件,因为它假设路径属于调用的包。
例如:

ls
 main.go
/notifications
/html/notify.template

运行 go run main.go

打开 html/notify.tpl: 没有这个文件或目录
英文:

I have a template in package notifications

/notifications
/html/notify.tpl

The issue is that if I call the functions of this package from a different path/package it can't find the file anymore as the program is assuming the path belongs to the package that is calling.
e.g.

ls
 main.go
/notifications
/html/notify.template

go run main.go

open html/notify.tpl: no such file or directory

答案1

得分: 1

你可以通过配置提供路径,使用一个已知的完全限定路径,使用相对于你的工作目录的路径(不推荐),或者以上三种方式的组合来指定路径。

英文:

You don't.

You either provide a path through configuration, use a well-known fully qualified path, use a path relative to your working directory (not recommended), or a combination of the three.

huangapple
  • 本文由 发表于 2014年7月19日 01:34:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/24830761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定