Golang解析来自第三方库的模板

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

Golang parsing template from third party lib

问题

我正在编写一个库,该库从其模板包中解析模板。当我在示例应用程序中使用它时,它会从自己的目录中读取模板,但库中的代码失败了。

这是库的链接-https://github.com/bangarharshit/bigpipe-golang,我在这一行遇到了问题-https://github.com/bangarharshit/bigpipe-golang/blob/master/Application.go#L66

从库中复制的代码:

templates, err := template.ParseFiles("templates/bigpipe.html")
if err != nil {
	return
}
英文:

I am writing a library which is parsing templates from its template package. When I am using it within a sample application its reading the template from its own directory but the code in libary is failing.

Here is the libary - https://github.com/bangarharshit/bigpipe-golang and I am facing issues with this line - https://github.com/bangarharshit/bigpipe-golang/blob/master/Application.go#L66

Copying code from lib -

templates, err := template.ParseFiles("templates/bigpipe.html")
if err != nil {
	return
}

答案1

得分: 0

一种替代方案是将文件内容复制到一个变量中,然后使用template.parse而不是template.parsefiles。

英文:

One alternative soultion is to copy content from file into a variable and use template.parse instead of template.parsefiles

huangapple
  • 本文由 发表于 2016年12月28日 10:36:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/41354631.html
匿名

发表评论

匿名网友

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

确定